
    !:hP                    T   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ 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l*m+Z+ d dl,m-Z-  G d dee      Z.y)    )Exchange)ImplicitAPIN)Any
CurrenciesCurrencyDepositAddressIntLedgerEntryLeverageTierLeverageTiersMarginModificationMarketNumOrder	OrderSide	OrderTypePositionStrTickersFundingRateTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)NotSupported)NetworkError)RateLimitExceeded)OnMaintenance)RequestTimeout)	TICK_SIZE)Precisec                       e Zd Zdef fdZd Zi fdefdZi fdefdZ	i fde
e   fdZi fdZi fdZd	 Zd
edefdZdddi fdededefdZd_d
edefdZdi fdedefdZi fdefdZdi fde
e   defdZdi fde
e   fdZd_dZddi fdededefdZdddi fdededefdZd_dZi fdZd Z i fded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fd%Z'di fdefd&Z(di fd'edefd(Z)dddi fdededefd)Z*dddi fdededefd*Z+dddi fdededefd+Z,dddi fdededefd,Z-dddi f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/Z0di fd0e
e   dede
e1   fd1Z2d_d2Z3d3 Z4dddi fd4e5dedede
e6   fd5Z7d_de6fd6Z8d7 Z9i fd4ede:fd8Z;d_de:fd9Z<dddi fd4e5dedefd:Z=dddi fd4e5dedefd;Z>di fd4ed"e!d<ede?fd=Z@d_d>ed?eAde?fd@ZBdA ZCdi fdBedefdCZDi fded"e!fdDZEi fded"e!fdEZFi fdedeGfdFZHd_deGfdGZIdi fde
e   deJfdHZKd`deJfdIZLi fdede
eM   fdJZNd_de
eM   fdKZOdddi fdededefdLZPi fdedeQfdMZRi fdedeQfdNZSd_deQfdOZTdddi fde5dedefdPZUd_dQZVi fdefdRZWdi fde
e   de
eX   fdSZYd_dTZZi fd4ed"e!dUedVede[f
dWZ\d_dXZ]di fdYede5fdZZ^ddi fd'eded e#d!e$d"e%d#e%de1fd[Z_d\ Z`g d]i ddfd^Za xZbS )axtreturnc                    | j                  t        t        |          i ddddddgddd	d
dddddi ddddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcddddddddddddedft        dgdhdidjdkdldmdndodpdqgdrdsdtdudvdwdvdvdvdvdvdvdvdvdvdvdxidui dydvdzdvd{dvd|dvd}dvd~dvddvddvddvddvddvddvddvddvddvddvddvdddvdidui dydvdzdvd{dvd|dvd}dvd~dvddvddvddvddvddvddvddvddvddvddvddvdddvdiddvdvdvdvdvdvdvdvdvdvdvdddwdvdvdvddvdvdvdddvidi ddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvii ddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvdvdvdvddi ddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvii ddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvdvdvdddvdvddvdvdddviddviddm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| 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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di dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        d t        dt        dt        dt        dt        dt        i dt        dt        dt        d	t        d
t        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        d t        d!t        d"t        d#t        d$t        d%t        d&t        d't        i d(t        d)t        d*t        d+t        d,t        d-t        d.t        d/t        d0t        d1t        d2t        d3t        d4t        d5t        d6t        d7t        d8t        i d9t        d:t        d;t        d<t        d=t        d>t        d?t        d@t        dAt        dBt        dCt        dDt        dEt        dFt        dGt        dHt        dIt        i dJt        dKt        dLt        dMt        dNt        dOt        dPt        dQt        dRt        dSt        dTt        dUt        dVt        dWt        dXt         dYt        dZt        t        t        t        t        t        t        d[t        t        t        d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmi dnddodpdqdrdsdsdsdtdui dvdwdxdydzd{d|d}d~dwddydd{ddddddddddddddddddddi ddddddddddddddddddddddddddddddddddi dddddddddddddddÐdēdŐdƓdǐdȓdɐdʓdːd̓d͐dΓdϐdГdѐdғdӐdԓdՐd֓dאdؐdِdڐdېdܐdݐdސdߜi dwdvdydxd{dzd}d|ddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddi dddddĐdÓdƐdœdȐdǓdʐdɓd̐d˓dΐd͓dАdϓdҐdѓdԐdӓd֐dՓdאddؐddddddِdddddddddddddddd ddd dddddddddddddd ddddddddddddddddddddddddddddddddd	ddddvddddddd
ddid	ddidddddddddd d ddddiddidddiddidd      S (  Nidr*   nameXT	countriesSC	rateLimitd   versionv4	certifiedFproThasCORSspotmarginswapfutureoption	addMarginborrowMargincancelAllOrderscancelOrdercancelOrderscreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreatePostOnlyOrdercreateReduceOnlyOrder	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesPerSymbolfetchCanceledOrdersfetchClosedOrdersfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawalsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchL3OrderBookfetchLedgerfetchLedgerEntryfetchLeveragefetchLeverageTiersfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrdersByStatusfetchOrderTradesfetchPositionfetchPositionsfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayMargin)setLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdrawprecisionModeurlszehttps://user-images.githubusercontent.com/14319357/232636712-466df2fc-560a-4ca4-aab2-b1d954a58e24.jpgzhttps://sapi.xt.comzhttps://fapi.xt.comzhttps://dapi.xt.comzhttps://api.xt.com)r:   linearinverseuserzhttps://xt.comz3https://www.xt.com/en/accounts/register?ref=9PTM9VWzhttps://doc.xt.com/z https://github.com/xtpub/api-doczhttps://www.xt.com/en/rate)logoapiwwwreferraldocfeesr   get   
   )
currenciesdepthklinesymboltickerzticker/bookzticker/pricez
ticker/24htimeztrade/historyztrade/recentzwallet/support/currencyz-future/market/v1/public/contract/risk-balancez.future/market/v1/public/contract/open-interestz/future/market/v1/public/leverage/bracket/detailz-future/market/v1/public/leverage/bracket/listz$future/market/v1/public/q/agg-tickerz%future/market/v1/public/q/agg-tickerszfuture/market/v1/public/q/dealzfuture/market/v1/public/q/depthz&future/market/v1/public/q/funding-ratez-future/market/v1/public/q/funding-rate-recordz%future/market/v1/public/q/index-pricezfuture/market/v1/public/q/klinez$future/market/v1/public/q/mark-pricez,future/market/v1/public/q/symbol-index-pricez+future/market/v1/public/q/symbol-mark-pricez future/market/v1/public/q/tickerz!future/market/v1/public/q/tickersgp=
ף
@)z$future/market/v1/public/symbol/coinsz%future/market/v1/public/symbol/detailz#future/market/v1/public/symbol/list)r:   r   r   )balancebalancesbatch-orderzdeposit/addresszdeposit/historyzhistory-order
open-orderorderorder/{orderId}tradezwithdraw/historyg?)r   r   zbalance/transferzbalance/account/transferws-token)r   r   r   r   )r   postdeleteputz#future/trade/v1/entrust/plan-detailz!future/trade/v1/entrust/plan-listz)future/trade/v1/entrust/plan-list-historyz%future/trade/v1/entrust/profit-detailz#future/trade/v1/entrust/profit-listzfuture/trade/v1/order/detailzfuture/trade/v1/order/listz"future/trade/v1/order/list-historyz future/trade/v1/order/trade-listzfuture/user/v1/account/infozfuture/user/v1/balance/billszfuture/user/v1/balance/detailz(future/user/v1/balance/funding-rate-listzfuture/user/v1/balance/listzfuture/user/v1/position/adlzfuture/user/v1/position/listz#future/user/v1/user/collection/listzfuture/user/v1/user/listen-keyz'future/trade/v1/entrust/cancel-all-planz.future/trade/v1/entrust/cancel-all-profit-stopz#future/trade/v1/entrust/cancel-planz*future/trade/v1/entrust/cancel-profit-stopz#future/trade/v1/entrust/create-planz%future/trade/v1/entrust/create-profitz*future/trade/v1/entrust/update-profit-stopzfuture/trade/v1/order/cancelz future/trade/v1/order/cancel-allzfuture/trade/v1/order/createz"future/trade/v1/order/create-batchzfuture/trade/v1/order/updatezfuture/user/v1/account/openz'future/user/v1/position/adjust-leveragez#future/user/v1/position/auto-marginz!future/user/v1/position/close-allzfuture/user/v1/position/margin)"future/user/v1/user/collection/add%future/user/v1/user/collection/cancelz#future/user/v1/position/change-type)r   r   )r   r   )zuser/accountuser/account/api-keyr   zuser/account/{apikeyId})r   r   r   r   )publicprivater   z0.00205000z0.001810000z0.001620000z0.001450000z0.0012150000z0.0010300000z0.0008600000z0.00071200000z0.00062500000z0.00056000000z0.000415000000z0.000330000000z0.0002)makertaker)	tierBased
percentager   r   tiers200000z0.000381000000z0.000365000000z0.0003410000000z0.00032z0.00028z0.0002450000000	100000000z0.00016	300000000z0.00012	500000000z0.00008z0.000588z0.00057z0.00054z0.00051z0.00048z0.00045z0.00033)r:   contract
exceptions400404429500502503AUTH_001AUTH_002AUTH_003AUTH_004AUTH_005AUTH_006AUTH_007AUTH_101AUTH_102AUTH_103AUTH_104AUTH_105AUTH_106
SYMBOL_001
SYMBOL_002
SYMBOL_003
SYMBOL_004
SYMBOL_005	ORDER_001	ORDER_002	ORDER_003	ORDER_004	ORDER_005	ORDER_006	ORDER_007ORDER_F0101ORDER_F0102ORDER_F0103ORDER_F0201ORDER_F0202ORDER_F0203ORDER_F0301ORDER_F0401ORDER_F0501ORDER_F0502ORDER_F0601
COMMON_001
COMMON_002
COMMON_003CURRENCY_001DEPOSIT_001DEPOSIT_002DEPOSIT_003DEPOSIT_004DEPOSIT_005DEPOSIT_006DEPOSIT_007DEPOSIT_008WITHDRAW_001WITHDRAW_002WITHDRAW_003WITHDRAW_004WITHDRAW_005WITHDRAW_006WITHDRAW_008WITHDRAW_009WITHDRAW_010WITHDRAW_011WITHDRAW_012WITHDRAW_013WITHDRAW_014WITHDRAW_015WITHDRAW_016WITHDRAW_017WITHDRAW_018WITHDRAW_019WITHDRAW_020WITHDRAW_021WITHDRAW_022WITHDRAW_023WITHDRAW_024WITHDRAW_025FUND_001FUND_002FUND_003FUND_004FUND_005FUND_014FUND_015FUND_016FUND_017FUND_018FUND_019FUND_020FUND_021FUND_022FUND_044TRANSFER_001TRANSFER_002TRANSFER_003TRANSFER_004TRANSFER_005TRANSFER_006TRANSFER_007TRANSFER_008TRANSFER_009)TRANSFER_010TRANSFER_011TRANSFER_012"symbol_not_support_trading_via_api"open_order_min_nominal_value_limitinsufficient_balance)z+The symbol does not support trading via APIz4Exceeds the minimum notional value of a single orderzinsufficient balance)exactbroad
timeframes1m5m15m30m1h2h4h6h8h1d3d1w1M)rD  rE  rF  rG  rH  rI  rJ  rK  rL  rM  rN  rO  rP  commonCurrenciesoptionsr   SPOTLEVERFINANCE	FUTURES_U	FUTURES_C)r:   leveragefinancer<   r=   r   r   ERC20EthereumTRC20TronBEP20zBNB Smart ChainBEP2zBNB-BEP2ETHTRONBNBAVAXzAVAX C-ChainGALzGAL(FT)ALEOz	ALEO(IOU)BTCBitcoinzXT Smart ChainETCzEthereum ClassicMATICPolygonLTCLitecoinBTS	BitSharesXRPRippleXLMzStellar NetworkADACardanoXWCzXWC-XWCDOGEdogecoinDCRDecredSiacoinXTZTezosZECZcashXMRMoneroLSKLiskATOMCosmosONTOntologyALGOAlgorandSOLzSOL-SOLDOTPolkadotZENHorizenFILFilecoinCHZchzICPzInternet ComputerKSMKusamaLUNATerraTHETAzTheta TokenFTMFantomVETVeChainNEARzNEAR ProtocolONEHarmonyKLAYKlaytnARArweaveCELTOKTEGLDzElrond eGoldCROz
CRO-CRONOSBCHzBitcoin CashGLMRMoonbeamLOOPzLOOP-LRCzREI NetworkzAstar NetworkOPTMMT-MMTTBC-TBCOMAX-OMAX CHAIN
GMMT chainZilliqa)REIASTROPMMTTBCOMAXGMMTZILr  r  r  r  r  r  r  r  )r  r  r  r  r  )adjustForTimeDifferencetimeDifferenceaccountsByIdnetworksnetworksById!createMarketBuyOrderRequiresPrice
recvWindowfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingrX  marketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergi )r  limitdaysBack	untilDays
marketTypesubTypesymbolRequired)r  triggerr  r  r  r  )r  r  r  r  r  r  r  )	r  r  r  r  r  r  r  r  r  )
r  r  r  daysBackCanceledr  r  r  r  r  r  r    )	sandboxrG   createOrdersrm   rr   rq   ru   rT   rn   extendsdefault)lastmarkindex)r  r  r  r  )r  r  )r  rG   rm   forDerivatives)r   r   )r  r:   r  r<   r=   )deep_extendsuperr*   describer'   parse_numberr#   r   r$   r%   r   r   r   r!   r    r   r&   )self	__class__s    A/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/xt.pyr  zxt.describe   s   b$ 8 : P=
$P=
DP=
 $P=
 P=
 tP=
 P=
 4P=
  ]]] $] 	]
 $] %] T] ] "4] t] ] '] /] 0] t]  &u!]" (#]$ T%]&  ']( )]*  +], &u-]. "5/]0 +E1]2 )%3]4 ,U5]6 &t7]8 $T9]: "4;]< =]> &t?]@ (A]B 1%C]D  E]F *5G]H *5I]J +EK]L &tM]N 'O]P (Q]R #DS]T *4U]V $UW]X "5Y]Z #E[]\ t]]^ #E_]`  a]b %dc]d +De]f g]h !%i]j  k]l dm]n $Uo]p +Eq]r "4s]t du]v !$w]x "5y]z t{]| &t}]~ #E]@  A]B !$C]D )%E]F )%G]H uI]J tK]L M]N TO]P tQ]R "5S]T #EU]V %eW]X &uY]Z '[]\ $U]]^  _]` !%a]b "5c]d #De]f +Eg]h i]j uk]l  $"!%#(  y]P=
T YUP=
V 1340	 (Q)6 5WP=
v  *+%'%&&'&'+,,-*+$%-.,-78 "   KQ La  Nq  LQ	 
 CA  DQ  =a  >q  Ea  LQ  DQ  >q  CA  KA  J1   ?! " @# $ EIEICD) 2   KQ La  Nq  LQ	 
 CA  DQ  =a  >q  Ea  LQ  DQ  >q  CA  KA  J1   ?! " @# $ EIEICD)  SAJ ()()+,/0/0-.*+%&/0%&01  &)(*0189()! ,-*+/0# .q 5> A1 ?  H  DQ	 
 B1  ;A  9!  A!  ?  :1  ;A  <Q  G  :1  :1   ;A! " B1# $ =a% (!Eq!La! B1! I!	!
 B1! DQ! I!! ;A! ?! ;A! A!! ;A! :1! Fq! B1!  @!!" =a#!$ CDEFCD)!++Z A1 ?  H  DQ	 
 B1  ;A  9!  A!  ?  :1  ;A  <Q  G  :1  :1   ;A! " B1# $ =a% (!Eq!La! B1! I!	!
 B1! DQ! I!! ;A! ?! ;A! A!! ;A! :1! Fq! B1!  @!!" =a#!$ CDEF'!+* Z -.45 
 -.45!
 3A  6q#mFGJwP=
L
 !%"&!..w7!..w7 "..s3T5F5Fw5OP!..v68I8I(8ST!..w79J9J89TU!..w79J9J89TU!..w79J9J89TU!..x8$:K:KH:UV!..x8$:K:KH:UV!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mh<WX!..z:D<M<Mh<WX"  "..s3T5F5Fw5OP!..v68I8I(8ST!..w79J9J89TU!..w79J9J89TU!..w79J9J89TU!..x8$:K:KH:UV!..x8$:K:KH:UV!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mh<WX!..z:D<M<Mh<WX"!%N "&"&!..x8!..x8 "..s3T5F5Fx5PQ!..x8$:K:KI:VW!..y94;L;LY;WX!..y94;L;LY;WX!..z:D<M<Mi<XY!..z:D<M<Mi<XY!..z:D<M<Mi<XY!..z:D<M<Mh<WX!..{;T=N=Ny=YZ!..{;T=N=Ny=YZ!..{;T=N=Ny=YZ" "..s3T5F5Fx5PQ!..x8$:K:KJ:WX!..y94;L;LY;WX!..y94;L;LY;WX!..z:D<M<Mi<XY!..z:D<M<Mi<XY!..z:D<M<Mi<XY!..z:D<M<Mi<XY!..{;T=N=Ny=YZ!..{;T=N=Ny=YZ!..{;T=N=Nx=XY"!OIM
P=
` m<m=m ,m =	m
 =m =m  3m  3m  3m  3m  3m  3m  3m  3m  3m   3!m"  3#m$  3%m&  0'm( !))m* !)+m, !)-m. !)/m0 !)1m2  3m4  !25m6  7m8  9m:  ;m<  =m>  !1?m@ "<AmB "<CmD "<EmF "<GmH "<ImJ "<KmL "<MmN "<OmP "<QmR "<SmT "<UmV !-WmX !-YmZ !*[m\ #J]m^ ":_m` "#3amb ":cmd ":emf ":gmh ":imj ":kml ":mmn #Jomp #Jqmr #$4smt #Jumv #Jwmx #Jymz #$4{m| #$4}m~ #Jm@ #$5AmB #$4CmD #$4EmF #JGmH #JImJ #JKmL #JMmN #JOmP #JQmR #$4SmT #$4UmV #JWmX #JYmZ #J[m\ #J]m^ 
_m`  1amb 
cmd emf  0gmh 
imj 
kml 
mmn 
omp 
qmr 
smt 
umv 
wmx 
ymz 
{m| #J}m~ #$5m@ #JAmB #$4CmD #$4EmF #$4GmH #NImJ #JKmL #JMmN %5$4$4:C:F,=Ym^ DMLX,=_taP=
J KP=
h iP=
j +0"#" '('))*!<Z<V< .< J	<
 :< F< ,< N< 9< K< 9< *< -< Y< :<  ;!<" 8#<$ ,%<& 9'<( 9)<* J+<, 8-<. )/<0 71<2 73<4 85<6 67<8 H9<: :;<< J=<> 9?<@ :A<B 9C<D :E<F 5G<H .I<J 8K<L GM<N ]O<P 8Q<R 9S<T OU<V 9W<X HY<Z )[<\ E]<^ N_<` <a<b >c<d Je<f Jg<h )+$$-($w<z9!9!G9! &w9! 	9!
 u9! %d9! '9! w9! 9!  9! e9! &u9! u9! u9! 9!  e!9!" t#9!$ U%9!& U'9!( e)9!* E+9!, f-9!. /9!0 19!2 u39!4 59!6 u79!8 99!: 5;9!< (=9!> e?9!@ VA9!B "7C9!D eE9!F uG9!H #FI9!J $VK9!L uM9!N fO9!P tQ9!R 6S9!T #FU9!V !%W9!X #EY9!Z [9!\ ]9!^ "5_9!` $Va9!b uc9!d  e9!f 4g9!h  %$'-"($q9!t 6:$IEkP=
v $&+(-,1,0).+06:#'#'"&#(	( #($)$)+/27/4#()$, %)&*!$$*%+&*#'*/& ',#'$)&*#'*/# '+!$#'$)&*#'*/( '+!$$*%+#'$)&*#'*/
$ '+!$$*,-%+#'$)&*#'*/*  #UM^ y  )(, %)$(%)-
 *.+/
$ %)%)&#( "#3 "#3 	 "#3 "#3 	YtwP=
 P P	    c                 B    | j                         | j                  d   z
  S )Nr  )millisecondsrR  )r  s    r  noncezxt.nonce1  s       "T\\2B%CCCr  c                 l    | j                  |      }| j                  |d      }| j                  |d      S )a.  
        fetches the current integer timestamp in milliseconds from the xt server

        https://doc.xt.com/#market1serverInfo

        :param dict params: extra parameters specific to the xt api endpoint
        :returns int: the current integer timestamp in milliseconds from the xt server
        result
serverTime)publicSpotGetTime
safe_valuesafe_integer)r  paramsresponsedatas       r  
fetch_timezxt.fetch_time4  s9     ))&1 x2  |44r  c                 :   | j                  |      | j                  |      g}|\  }}| j                  |dg       }| j                  |dg       }| j                  |dg       }| j                  |d      }i }	t	        dt        |            D ]  }
||
   }| j                  |d      }| j                  |      }| j                  | j                  | j                  |d                  }| j                  ||i       }| j                  |dg       }i }d}d}d}d}d}t	        dt        |            D ]  }||   }| j                  |d	      }| j                  |      }| j                  |d
      }|r|n|}| j                  |d      }|r|n|}|xr |}|r|n|}| j                  |d      }|||nt        j                  ||      }| j                  |d      }|||nt        j                  ||      }|||d|| j                  |      |||ddd| j                  |      ddddddd
||<    | j                  |d      } d}!| dk(  rd}!nd}!|||| j                  |d      || j                  |      |||||!ddd| j                  |      ddddddd|	|<    |	S )a  
        fetches all available currencies on an exchange

        https://doc.xt.com/#deposit_withdrawalsupportedCurrenciesGet

        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: an associative dictionary of currencies
        r  r   currencyr   maxPrecisionsupportChainsNFchaindepositEnabledwithdrawEnabledwithdrawFeeAmountwithdrawMinAmountminmax)amountr   deposit)
infor-   networkr.   activefee	precisionr  r   limitstypeFTcryptootherfullName)r  r-   coder.   r  r	  r
  r  r   r  r  r  )"publicSpotGetWalletSupportCurrencypublicSpotGetCurrenciesr  index_byrangelensafe_stringsafe_currency_coder  parse_precisionnetwork_id_to_coder(   
string_min)"r  r  promisesRawchainsResponsecurrenciesResponse
chainsDatacurrenciesResultcurrenciesDatachainsDataIndexedr  ientry
currencyIdr  minPrecisionnetworkEntryrawNetworksr  minWithdrawStringminWithdrawFeeStringr  r  r   j
rawNetwork	networkIdr  r  r  networkActivewithdrawFeeStringminNetworkWithdrawStringtypeRawr  s"                                     r  fetch_currencieszxt.fetch_currenciesK  sk    >>vFHdHdekHlm-8**h __^XrB
??+=xL)9<L MM*jAq#n-. V	A"1%E))%<J**:6D,,T-A-A$BRBRSXZhBi-jkL??+<j"ML//,LKH $#' FGH1c+./ ((^
 ,,ZA	11)<!%=M!N-;.'"&//*>O"P/>?X . B?+8v$($4$4ZAT$U!$0AUA]+<dkdvdv  xI  K_  e`(+/+;+;JH[+\(+7EVE^(@elewew  yQ  Sd  fe%&#& +,,->?!-- / $(#'#
 $(#4#45M#N#'%
 $(#'$%!!(R &&uf5GD$ ((
; (()=>)"$$  $#
  $001BC#!
  $# F4LyV	n r  c                     | j                   d   r| j                          | j                  |      | j                  |      g}|}|d   }|d   }| j	                  ||      S )a*  
        retrieves data on all markets for xt

        https://doc.xt.com/#market2symbol
        https://doc.xt.com/#futures_quotesgetSymbols

        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict[]: an array of objects representing market data
        r  r   r   )rR  load_time_differencefetch_spot_marketsfetch_swap_and_future_marketsarray_concat)r  r  promisesUnresolvedpromisesspotMarketsswapAndFutureMarketss         r  fetch_marketszxt.fetch_markets  so     <<12%%'##F+..v6
 &qk'{  .BCCr  c                     | j                  |      }| j                  |di       }| j                  |dg       }| j                  |      S )Nr  symbols)publicSpotGetSymbolr  parse_markets)r  r  r  r  r>  s        r  r5  zxt.fetch_spot_markets  sJ    ++F3j x26//$	26!!'**r  c                     | j                  |      | j                  |      g}| j                  | j                  |d   dg       | j                  |d   dg             }| j	                  |      S )Nr   r  r   )-publicLinearGetFutureMarketV1PublicSymbolList.publicInverseGetFutureMarketV1PublicSymbolListr7  r  r@  )r  r  marketsr;  s       r  r6  z xt.fetch_swap_and_future_markets6  s    EEfMt  PC  PC  DJ  PK  L~  $00XWY1Z\`\k\klstulv  yA  CE  ]F   G!!"677r  c                     g }t        dt        |            D ]%  }|j                  | j                  ||                ' |S )Nr   )r  r  appendparse_market)r  rD  r  r#  s       r  r@  zxt.parse_marketsy  sA    q#g,' 	9AMM$++GAJ78	9r  marketc                    | j                  |d      }| j                  |dd      }| j                  |dd      }| j                  |      }| j                  |      }| j                  |d      }|dz   |z   }| j                  |dg       }	d }
d }d }d }d }d }d }t	        d	t        |	            D ]  }|	|   }| j                  |d
      }|dk(  r6| j                  |d      }
| j                  |d      }| j                  |d      }|dk(  r| j                  |d      }|dk(  sr| j                  |d      }| j                  |d      } |0| j                  | j                  | j                  |d                  }| j                  |d      }d }d }d }d }d }d}d}d}d}d}|dk(  r|dz   |z   }|}|}d}d}n|dk(  r|dz   |z   }|}|}d}d}|| j                  |d      }| j                  |d      }|dk7  r|dz   | j                  |      z   }d}d}nd}d}| j                  |d      }
| j                  |d       }| j                  |d!      }| j                  |d"      }| j                  |d#      }d}d}d} |r| j                  |d$d      } n+|d%k(  r&| j                  |d&      r| j                  |d'      rd} | j                  i d(|d|d)|d*|d+|d,|d-|d.|d/|d|d0d d|d|d1dd2| d3|d4||| j                  |d5      | j                  |d6      | j                  |d7      || j                  |      d d | j                  | j                  | j                  |d8                  || j                  | j                  | j                  |d9                  | j                  | j                  | j                  |d:                  d;| j                  d<      d d=|
|d=||d=||d=d>|d?      S )@Nr   baseCurrencybaseCoinquoteCurrency	quoteCoinstate/filtersr   filterQUANTITYr  r  tickSize	QUOTE_QTYPRICEquantityPrecisionunderlyingTypeFTr:   U_BASED:
COIN_BASEDdeliveryDateproductType	perpetual-r=   r<   minQtyminNotionalmaxNotionalminPricemaxPrice	isOpenApiONLINEtradingEnabledopenapiEnabledr-   basequotesettlebaseIdquoteIdsettleIdr  r;   r>   r  r   r   takerFeemakerFeecontractSizepricePrecisionbaseCoinPrecisionquoteCoinPrecision)pricer  rh  ri  1r  )rX  r  rt  cost)r   r   r   rp  expiryexpiryDatetimestrike
optionTyper
  r  r  )r  safe_string_2r  r  r  r  safe_numberr  r  r  yymmddsafe_market_structureiso8601)!r  rH  r-   rk  rl  rh  ri  rN  r   rP  	minAmount	maxAmountminCostmaxCostrb  rc  amountPrecisionr#  r$  rQ  rW  r   r   rm  rj  rw  r=   r<   r   r:   r  r\  isActives!                                    r  rG  zxt.parse_market  sA   j fh/##FNJG$$V_kJ&&v.''0  1e#//&)R8		q#g,' 	:AAJE%%eX6F# ,,UE:	 ,,UE:	"&"2"25*"E$**5%8 ++E59++E59	: ""//0D0DTEUEUV\^qEr0stO))&2BCY&c\E)FHFFG|+c\D(FHFFG%&&v~>F**6=AKk)#F(;;((:I&&v}=G&&v}=G''
;H''
;HHDv{EBH!@P(QX\XgXghn  qA  YB)) 3+
"3+
f3+
 D3+
 U	3+

 f3+
 f3+
 w3+
 3+
 D3+
 D3+
 d3+
 D3+
 f3+
 e3+
 h3+
  !3+
" f#3+
$ %%fj9%%fj9 ,,V^D"ll62**4+?+?@P@PQWYi@j+kl)))$*>*>t?O?OPVXk?l*mn**4+?+?@P@PQWYm@n+op	  ,,S1
 %$
 $#
 #"$ e3+
 3 3	r  rD  Nr   sincer  c           	         | j                          d}| j                  |ddd      \  }}|r| j                  d|||||d      S | j                  |      }|d   | j	                  | j
                  ||      d}|||d<   |||d	<   nd|d	<   | j                  |d
      }	| j                  |d
g      }|	|	|d<   d}
|d   r"| j                  | j                  ||            }
nH|d   r"| j                  | j                  ||            }
n!| 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://doc.xt.com/#market4kline
        https://doc.xt.com/#futures_quotesgetKLine

        :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 xt api endpoint
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Frn   paginater  r-   )r   intervalN	startTimer  untilendTimer   r   r  )load_marketshandle_option_and_params"fetch_paginated_call_deterministicrH  r  rC  r  omit)publicLinearGetFutureMarketV1PublicQKlineextend*publicInverseGetFutureMarketV1PublicQKlinepublicSpotGetKliner  parse_ohlcvs)r  r   	timeframer  r  r  r  rH  requestr  r  ohlcvss               r  fetch_ohlcvzxt.fetch_ohlcvt  s     	88z[`a&::<QVX]_hjprvwwV$Tl(()YO
 #(GK $GG#GG!!&'26G9-!&GI(EEdkkRY[aFbcHIFFt{{SZ\bGcdH..t{{7F/KLHT 8R8  E5IIr  c           
          |d   rdnd}| j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d	|      gS )
Nr   vatohlcq)r  r|  safe_number_2)r  ohlcvrH  volumeIndexs       r  parse_ohlcvzxt.parse_ohlcv  s~    8 %Y/cceS)UC(UC(UC(UC(uc;7
 	
r  c                    | j                          | j                  |      }d|d   i}d}|d   r3|t        |d      |d<   | j                  | j	                  ||            }nd|t        |d      |d<   nd|d<   |d	   r"| j                  | j	                  ||            }n&|d
   r!| j                  | j	                  ||            }| j                  |di       }| j                  |dd      }|d   r*| j                  |||      }	| j                  |d      |	d<   |	S | j                  |||dd      }
| j                  |dd      |
d<   |
S )aR  

        https://doc.xt.com/#market3depth
        https://doc.xt.com/#futures_quotesgetDepth

        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified market symbol 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 xt api endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/en/latest/manual.html#order-book-structure>` indexed by market symbols
        r   r-   Nr:   i  r  2   levelr   r   r  	timestampr  lastUpdateIdr  br  u)r  rH  r  publicSpotGetDepthr  )publicLinearGetFutureMarketV1PublicQDepth*publicInverseGetFutureMarketV1PublicQDepthr  safe_integer_2parse_order_bookr  )r  r   r  r  rH  r  r  	orderBookr  obswapObs              r  fetch_order_bookzxt.fetch_order_book  sk    	V$fTl
 &> #&uc? ..t{{7F/KLH #&ub> #% hII$++V]_eJfg	"JJ4;;W^`fKgh^ OOHh;	''	;D	&>&&y&)DB++I~FBwKI&&y&)S#N--inMwr  c                    | j                          | j                  |      }d|d   i}d}|d   r"| j                  | j                  ||            }nH|d   r"| j	                  | j                  ||            }n!| j                  | j                  ||            }| j                  |d      }|d   r| j                  |d   |      S | j                  ||      S )	a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://doc.xt.com/#market10ticker24h
        https://doc.xt.com/#futures_quotesgetAggTicker

        :param str symbol: unified market symbol to fetch the ticker for
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/en/latest/manual.html#ticker-structure>`
        r   r-   Nr   r   r  r:   r   )r  rH  -publicLinearGetFutureMarketV1PublicQAggTickerr  .publicInverseGetFutureMarketV1PublicQAggTickerpublicSpotGetTicker24hr  parse_ticker)r  r   r  rH  r  r  r   s          r  fetch_tickerzxt.fetch_tickerH  s     	V$fTl
 (II$++V]_eJfgHIJJ4;;W^`fKghH224;;w3OPH^ 84&>$$VAY77  00r  r>  c                    | j                          d}|%| j                  |      }| j                  |d         }i }d}d}d}| j                  d||      \  }}| j	                  d||      \  }}|dk(  r"| j                  | j                  ||            }nR|dk(  s
|dk(  s|dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }i }	t        dt        |            D ]!  }
| j                  ||
   |      }|d	   }||	|<   # | j                  |	d	|      S )
aJ  
        fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market

        https://doc.xt.com/#market10ticker24h
        https://doc.xt.com/#futures_quotesgetAggTickers

        :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 xt api endpoint
        :returns dict: an array of `ticker structures <https://docs.ccxt.com/en/latest/manual.html#ticker-structure>`
        Nr   r~   r   r   r<   r=   r  r   )r  market_symbolsrH  handle_market_type_and_paramshandle_sub_type_and_params/publicInverseGetFutureMarketV1PublicQAggTickersr  .publicLinearGetFutureMarketV1PublicQAggTickersr  r  r  r  r  filter_by_array)r  r>  r  rH  r  r  r  r  tickersr  r#  r   r   s                r  fetch_tickerszxt.fetch_tickers  si    	))'2G[[,F99.&RXYf99.&RXYiKKDKKX_agLhiH!tv~48;KJJ4;;W^`fKghH224;;w3OPHb //(Hb9q#g,' 	$A&&wqz6:FH%F#F6N	$ ##FHg>>r  c                 h   | j                          | j                  |      }i }d}|| j                  |d         }d}| j                  d||      \  }}|t	        | j
                  dz         | j                  | j                  ||            }| j                  |dg       }| j                  ||      S )a  
        fetches the bid and ask price and volume for multiple markets

        https://doc.xt.com/#market9tickerBook

        :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 xt api endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/en/latest/manual.html#ticker-structure>`
        Nr   rM   z^ fetchBidsAsks() is not available for swap and future markets, only spot markets are supportedr  )
r  r  rH  r  r"   r-   publicSpotGetTickerBookr  r  parse_tickers)r  r>  r  r  rH  r  r  r  s           r  fetch_bids_askszxt.fetch_bids_asks  s     	%%g.[[,F99/6SYZtww  *J   J  K  K//GV0LM$ //(Hb9!!'733r  c           	      <   | j                  |d      }||d   nd }d|v xs d|v }||rdnd}| j                  ||d|      }|d   }| j                  |d	      }| j                  |d
d      }|t	        j
                  |d      }| j                  i 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| j                  |d      d| j                  |d      d| j                  |d      d d d!| j                  |d      d"| j                  |      d#d d | j                  |d$d%      |d&|      S )'Nsr  cvaqr:   r   _r   r  crr100r  datetimehighr  lowr  bidbp	bidVolumebqaskap	askVolumevwapopenr  closer  r  previousClosechanger   averager  r  )
baseVolumequoteVolumer  )r  safe_marketr  r{  r(   
string_mulsafe_tickerr  r|  r  r  )	r  r   rH  marketIdr  hasSpotKeysr   r  r   s	            r  r  zxt.parse_ticker  s@   \ ##FC0(.(:VF^
v~:46>#.JJ!!(FCD!%%fc2	''c:
! ++J>J !
f!
!
 Y/!
 D$$VS1	!

 4##FC0!
 4##FD1!
 ))&$7!
 4##FD1!
 ))&$7!
 D!
 D$$VS1!
 T%%fc2!
 D$$VS1!
 T!
 d&&vt4!
  $++J7!!
" t#!
$ --fc3?)!
* + 	r  c                    | j                          | j                  |      }d|d   i}d}|d   r)|||d<   | j                  | j                  ||            }nT|||d<   |d   r"| j	                  | j                  ||            }n&|d   r!| j                  | j                  ||            }| j                  |d	g       }| j                  ||      S )
aA  
        get the list of most recent trades for a particular symbol

        https://doc.xt.com/#market5tradeRecent
        https://doc.xt.com/#futures_quotesgetDeal

        :param str symbol: unified market symbol 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 xt api endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
        r   r-   Nr:   r  numr   r   r  )r  rH  publicSpotGetTradeRecentr  (publicLinearGetFutureMarketV1PublicQDeal)publicInverseGetFutureMarketV1PublicQDealr  parse_trades)	r  r   r  r  r  rH  r  r  tradess	            r  fetch_tradeszxt.fetch_trades_  s     	V$fTl
 &> #( 44T[[&5QRH !&hHHU\^dIef	"II$++V]_eJfgJ 8R8  00r  c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   d}d}d}	| j                  d||      \  }}| j                  d||      \  }}|
|dk(  s|dk(  rP|||d<   |d	k(  r"| j	                  | j                  ||            }	nl| j                  | j                  ||            }	nJd}
| j                  d|      \  }
}|
d
nd}||d<   |||d<   | j                  | j                  ||            }	| j                  |	di       }| j                  |dg       }| j                  ||||      S )a&  
        fetch all trades made by the user

        https://doc.xt.com/#tradetradeGet
        https://doc.xt.com/#futures_ordergetTrades

        :param str [symbol]: unified market symbol 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 xt api endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
        Nr-   r   r  rm   r<   r=   sizer   rT  rS  bizTyper  r  items)r  rH  r  r  ,privateInverseGetFutureTradeV1OrderTradeListr  +privateLinearGetFutureTradeV1OrderTradeListhandle_margin_mode_and_paramsprivateSpotGetTrader  r  )r  r   r  r  r  r  rH  r  r  r  r  marginOrSpotRequestr  r  s                 r  fetch_my_tradeszxt.fetch_my_trades  s    	[[(F &tGH#(GK 99/6SYZf99/6SYZTV^9I "')#LLT[[Y`bhMijKKDKKX_agLhiJ!%!C!COU[!\J.8.D'6!4GI #( //GV0LMHv x26w3  >>r  c                    | j                  |dd      }||d   nd }d|v xs
 d|v xs d|v }||rdnd}| j                  ||d	|      }d }d }| j                  |d      }|	|rd
nd}d}ne| j                  |d      }	|	|	}n| j                  |d      }
|
|
rdnd}| j                  |d      }||}n| j	                  |d      }|	|dk(  rdnd
}| j                  |g d      }| j                  |dd      }d }|dk(  r|}nc|9t        j                  | j	                  |d      | j                  |d               }n(t        j                  || j                  |d               }| j                  || j                  |g d      || j                  |      |d   | j                  |dd      | j                  |d      ||| j                  |dd      |d | j                  | j                  |dd            | j	                  |d      d d!|      S )"Nr  r   r  r  r  oir:   r   r  sellbuyr   
takerMakerisMakerr   	orderSidemBID)r  r   r  r  quantityr  rp  )r#  tradeIdexecIdorderId	orderTypeprt  feeCurrencyfeeCoinr	  r  rv  )r  r-   r  r  r   r   r  sidetakerOrMakerrt  r  rv  r	  )r{  r  	safe_boolsafe_string_lowerr  safe_integer_nr(   r  number_to_string
safe_tradesafe_string_nr  r  )r  r   rH  r  r  r  r  r  isBuyerMakerr  r   r  bidOrAskr  r  r  s                   r  parse_tradezxt.parse_trade  sc   X %%eS(;(.(:VF^
e|Oe);O#.JJ!!(FCD~~eS1#)6uD"L//|DJ%)..	:&.577L..ukBI$ ++E37'%-%65VD''/IJ	%%eS*=F ++D,<,<UC,H$J_J_`fgu`vJwx ++Hd6K6KFSaLb6cd$$U,FG"Y/X&''y$?**5+>(''sG< 33D4F4Fum]f4gh((6 
" # 	r  c                    | j                          d}d}d}| j                  dd|      \  }}| j                  dd|      \  }}|dk(  xs |dk(  }|dk(  r| j                  |      }n*|dk(  s|r| j	                  |      }n| j                  |      }d}||r| j                  |dg       }n&| j                  |di       }| j                  |dg       }| j                  |      S )	a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://doc.xt.com/#balancebalancesGet
        https://doc.xt.com/#futures_usergetBalances

        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/en/latest/manual.html?#balance-structure>`
        NrL   r<   r=   r   r   r  assets)r  r  r  (privateInverseGetFutureUserV1BalanceList'privateLinearGetFutureUserV1BalanceListprivateSpotGetBalancesr  parse_balance)r  r  r  r  r  isContractWalletr   r  s           r  fetch_balancezxt.fetch_balance  s     	99.$PVWf99.$PVW!V^B1AiDDVLH!&6CCFKH226:HZ $4x2>H??8Xr:DtXr:H!!(++r  c                 &   d|i}t        dt        |            D ]  }||   }| j                  |dd      }| j                  |      }| j	                         }| j                  |dd      }| j                  |d      }	| j                  |dd	      }
|	\t        j                  | j                  |d
      | j                  |d            }t        j                  | j                  |d      |      }	||d<   |	|d<   |
|d<   |||<    | j                  |      S )Nr  r   r  coinavailableAmountavailableBalancefrozenAmounttotalAmountwalletBalancecrossedMarginisolatedMarginopenOrderMarginFrozenfreeusedtotal)	r  r  r{  r  accountr  r(   
string_addsafe_balance)r  r  r  r#  r   r%  r  r-  r*  r+  r,  crossedAndIsolatedMargins               r  r  zxt.parse_balance  s:   6 (#q#h-( 	#AqkG++GZHJ**:6DllnG%%g/@BTUD##G^<D&&wOE|+2+=+=d>N>NwXg>hjnjzjz  |C  EU  kV  ,W())$*:*:7D[*\^vw"GFO"GFO$GG"F4L	#   ((r  rv  c                     | j                          | j                  |      }|d   st        | j                  dz         | j	                  |dd|d|      S )a  

        https://doc.xt.com/#orderorderPost

        create a market buy order by providing the symbol and cost
        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r:   z9 createMarketBuyOrderWithCost() supports spot orders onlyrH  r  r   )r  rH  r"   r-   create_order)r  r   rv  r  rH  s        r  !create_market_buy_order_with_costz$xt.create_market_buy_order_with_cost'	  sU     	V$f~tww)ddee  5$6JJr  r  r  r  rt  c                     | j                          | j                  |      }|d   }|d   r| j                  ||||||      S | j                  ||||||      S )a  
        create a trade order

        https://doc.xt.com/#orderorderPost
        https://doc.xt.com/#futures_ordercreate
        https://doc.xt.com/#futures_entrustcreatePlan
        https://doc.xt.com/#futures_entrustcreateProfit

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency
        :param float [price]: the price to fulfill the order, in units of the quote currency, can be ignored in market orders
        :param dict params: extra parameters specific to the xt api endpoint
        :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK' or 'GTX'
        :param str [params.entrustType]: 'TAKE_PROFIT', 'STOP', 'TAKE_PROFIT_MARKET', 'STOP_MARKET', 'TRAILING_STOP_MARKET', required if stopPrice is defined, currently isn't functioning on xt's side
        :param str [params.triggerPriceType]: 'INDEX_PRICE', 'MARK_PRICE', 'LATEST_PRICE', required if stopPrice is defined
        :param float [params.triggerPrice]: price to trigger a stop order
        :param float [params.stopPrice]: alias for triggerPrice
        :param float [params.stopLoss]: price to set a stop-loss on an open position
        :param float [params.takeProfit]: price to set a take-profit on an open position
        :returns dict: an `order structure <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        r   r:   )r  rH  create_spot_ordercreate_contract_order)r  r   r  r  r  rt  r  rH  s           r  r2  zxt.create_order8	  sf    0 	V$!&>))&$feVTT--fdD&%QWXXr  c                    | j                          | j                  |      }|d   |j                         |j                         d}d }	d }
| j                  d|      \  }
}|
dnd}||d<   |dk(  r| j	                  |dd	      }	|d
k(  r| j                  |d      }| j                  |d      }| j                  | j                  dd      }|rq||t        | j                  dz         | j                  |      }| j                  |      }d }|t        j                  ||      }n|}| j                  ||      |d<   nD||n|}| j                  ||      |d<   n(| j	                  |dd      }	| j                  ||      |d<   |dk(  s|dk(  r| j!                  ||      |d<   |	|d<   | j#                  | j%                  ||            }| j'                  |di       }| j)                  ||      S )Nr-   )r   r  r  rG   rT  rS  r  rH  r  r  r  rv  r  Ta   createOrder() requires a price argument or cost in params for market buy orders on spot markets to calculate the total amount to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to False and pass in the cost to spend into the amount parameterquoteQtyGTCrt  r  r  r  r  )r  rH  upperr  safe_string_upperr  r  r  rR  r!   r-   r  r(   r  cost_to_precisionprice_to_precisionamount_to_precisionprivateSpotPostOrderr  r  parse_order)r  r   r  r  r  rt  r  rH  r  r  r  r  rv  r  amountStringpriceStringcostCalculated
amountCostr  r   s                       r  r5  zxt.create_spot_orderX	  s   V$TlJJLJJL

 
!??vV
F*4*@gv0	800NKu}''766248NN4<<Qtvz4{14}$,*477  6P  ,P  Q  Q'+'<'<V'D&*&;&;E&B.2 ,-4-?-?k-ZN-1N.2.D.DV^.\
+*.*:J*.*@*@*TGJ'00NK#66vuEGGFN"&":":66"JGJ!,,,T[[&-IJ (B7v..r  c                    | j                          | j                  |      }|d   | j                  ||      d}| j                  |d      }	|	|	|d<   | j	                  |dd      }
|dk(  r|
rdnd}||d	<   n|
rdnd}||d	<   d }| j                  |d
d      }| j                  |dd      }| j                  |dd      }|d u}|d u}|d u}||s|s| j                  ||      |d<   |r| j                  |dd      |d<   | j                  |dd      |d<   |j                         |d<   | j                  ||      |d<   |dk(  rdnd}||d<   | j                  |d
      }|d   r#| j                  | j                  ||            }n/|d   r)| j                  | j                  ||            }n|s|r|r| j                  ||      |d<   n| j                  ||      |d<   | j                  |ddg      }|d   r"| j                  | j                  ||            }n|d   r| j                  | j                  ||            }ns|j                         |d<   |j                         |d<   |d   r"| j                  | j                  ||            }n&|d   r!| j!                  | j                  ||            }| j#                  ||      S )Nr-   )r   origQtyr  
reduceOnlyFr  SHORTLONGpositionSider  	stopPricestopLosstriggerStopPrice
takeProfittriggerProfitPricert  r9  r  LATEST_PRICEr  rH  STOP_MARKETSTOPentrustTyper   r   r  )r  rH  r>  r;  r  r  r=  r  r:  r  /privateLinearPostFutureTradeV1EntrustCreatePlanr  0privateInversePostFutureTradeV1EntrustCreatePlan1privateLinearPostFutureTradeV1EntrustCreateProfit2privateInversePostFutureTradeV1EntrustCreateProfit)privateLinearPostFutureTradeV1OrderCreate*privateInversePostFutureTradeV1OrderCreater@  )r  r   r  r  r  rt  r  rH  r  r  rG  requestTyper  r  rL  rN  	isTrigger
isStopLossisTakeProfitrS  s                       r  r6  zxt.create_contract_order	  s   V$Tl//?
 ,,V]C"%0GM"__V\5A
5=&0'vK&1GN#%/&gK&1GN#))&.+N%%fj:LM''>RS
!-	d*
"$.#'#:#:65#I %)%;%;FMSX%YGM"*.*:*:6CUWe*fG&'#'::<GK #'#:#:6<#PGK ,0H,<-6K%0GM"YYv~6FhOOPTP[P[\cekPlm	"PPQUQ\Q\]dflQmn<.2.E.Efh.W*+040G0GPZ0[,-YYv
L'ABFhQQRVR]R]^egmRno	"RRSWS^S^_fhnSop#'::<GK #'::<GK hII$++V]_eJfg	"JJ4;;W^`fKgh &11r  r-   c                    | j                          d}|| j                  |      }i }d}d}d}| j                  d||      \  }}| j                  d||      \  }}| j	                  |d      }	| j	                  |d      }
|	r||d<   n|
r||d<   n||d<   |	r[| j                  |d      }|dk(  r"| j                  | j                  ||            }n| j                  | j                  ||            }n|
r[| j                  |d      }|dk(  r"| j                  | j                  ||            }n| j                  | j                  ||            }ny|dk(  r"| j                  | j                  ||            }nR|d	k(  s
|d
k(  s|dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )a  
        fetches information on an order made by the user

        https://doc.xt.com/#orderorderGet
        https://doc.xt.com/#futures_ordergetById
        https://doc.xt.com/#futures_entrustgetPlanById
        https://doc.xt.com/#futures_entrustgetProfitById

        :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 xt api endpoint
        :param bool [params.trigger]: if the order is a trigger order or not
        :param bool [params.stopLossTakeProfit]: if the order is a stop-loss or take-profit order
        :returns dict: An `order structure <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        Nrr   stopstopLossTakeProfit	entrustIdprofitIdr  r   r   r<   r=   r  )r  rH  r  r  r  r  /privateInverseGetFutureTradeV1EntrustPlanDetailr  .privateLinearGetFutureTradeV1EntrustPlanDetail1privateInverseGetFutureTradeV1EntrustProfitDetail0privateLinearGetFutureTradeV1EntrustProfitDetail)privateInverseGetFutureTradeV1OrderDetail(privateLinearGetFutureTradeV1OrderDetailprivateSpotGetOrderOrderIdr@  )r  r-   r   r  rH  r  r  r  r  r  r`  r   s               r  fetch_orderzxt.fetch_order	  s     	[[(F99,PVWf99,PVW//&&1!__V5IJ#%GK "$GJ!#GIYYvv.F)#OOPTP[P[\cekPlmNNt{{[bdjOklYYv';<F)#QQRVR]R]^egmRnoPPQUQ\Q\]dflQmn	!EEdkkRY[aFbcH!tv~48;KDDT[[QXZ`EabH66t{{7F7STHl (B7v..r  c                 n   | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   d}d}d}	| j                  d||      \  }}| j                  d||      \  }}| j	                  |dd      }
|
r]| j                  |ddg      }|d	k(  r"| j                  | j                  ||            }	n| j                  | j                  ||            }	n|d	k(  r"| j                  | j                  ||            }	nt|d
k(  s
|dk(  s|dk(  r"| j                  | j                  ||            }	nCd}| j                  d|      \  }}|dnd}||d<   | j                  | j                  ||            }	| j                  |	di       }| j                  |dg       }| j                  ||||      S )a  
        fetches information on multiple orders made by the user

        https://doc.xt.com/#orderhistoryOrderGet
        https://doc.xt.com/#futures_ordergetHistory
        https://doc.xt.com/#futures_entrustgetPlanHistory

        :param str [symbol]: unified market symbol of the market the orders were made in
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict params: extra parameters specific to the xt api endpoint
        :param bool [params.trigger]: if the order is a trigger order or not
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        Nr-   r   r  r  ru   r  r_  r   r   r<   r=   rT  rS  r  r  r  )r  rH  r  r  safe_value_2r  4privateInverseGetFutureTradeV1EntrustPlanListHistoryr  3privateLinearGetFutureTradeV1EntrustPlanListHistory.privateInverseGetFutureTradeV1OrderListHistory-privateLinearGetFutureTradeV1OrderListHistoryr  privateSpotGetHistoryOrderr  parse_orders)r  r   r  r  r  r  rH  r  r  r  r  r  r  r  orderss                  r  fetch_orderszxt.fetch_orders|
  s    	[[(F &tGH#(GK $GG99-QWXf99-QWX##FIv>YYv	6':;F)#TTUYU`U`ahjpUqrSSTXT_T_`gioTpq	!JJ4;;W^`fKghH!tv~48;KII$++V]_eJfgHJ!%!C!CMSY!ZJ.8.D'6!4GI66t{{7F7STH^ x26w3  >>r  c                    | j                          i }d }|| j                  |      }|d   |d<   d }d }	d }
| j                  d||      \  }}| j                  d||      \  }	}| j	                  |d      }| j	                  |d      }|dk(  r|s|rd|d<   n7|	5d	|d<   n/|d
k(  r|s|rd|d<   n d|d<   n|dk(  r|s|rd|d<   nd|d<   n||d<   |s|s|	
|dk(  s|dk(  r|||d<   |||d<   |r]| j                  |d      }|	dk(  r#| j                  | j                  ||            }
nM| j                  | j                  ||            }
n*|r[| j                  |d      }|	dk(  r"| j                  | j                  ||            }
n| j                  | j                  ||            }
n|	
|dk(  s|dk(  rI|	dk(  r"| j                  | j                  ||            }
n| j                  | j                  ||            }
nxd }| j                  d|      \  }}|dnd}||d<   |dk7  r0|||d<   |||d<   | j                  | j                  ||            }
n!| j                  | j                  ||            }
|dk(  xr |	d u }| j	                  |
di       }|r| j	                  |
dg       n| j	                  |dg       }| j!                  ||||      S )Nr-   r   rv   r_  r`  r  NOT_TRIGGEREDrN  NEWclosed	TRIGGEREDFILLEDcanceledUSER_REVOCATIONCANCELEDr<   r=   r  r  r   rT  rS  r  r  r  r  )r  rH  r  r  r  r  -privateInverseGetFutureTradeV1EntrustPlanListr  ,privateLinearGetFutureTradeV1EntrustPlanList/privateInverseGetFutureTradeV1EntrustProfitList.privateLinearGetFutureTradeV1EntrustProfitList'privateInverseGetFutureTradeV1OrderList&privateLinearGetFutureTradeV1OrderListr  rq  privateSpotGetOpenOrderrr  )r  statusr   r  r  r  r  rH  r  r  r  r  r`  r  r  isSpotOpenOrdersr  rs  s                     r  fetch_orders_by_statuszxt.fetch_orders_by_status  sP   [[(F &tGH99:OQWY_`f99:OQWY_`//&&1!__V5IJV,#2 $#( x,#. #+ z!,#4 #- %GG(W-@dfnZ^bjZj ',$ "'YYvv.F)#MMdkkZaciNjkLLT[[Y`bhMijYYv';<F)#OOPTP[P[\cekPlmNNt{{[bdjOkl!tv~48;K)#GGT[]cHdeFFt{{SZ\bGcdJ!%!C!CDY[a!bJ.8.D'6!4GI$+0GK($',GG$::4;;wPV;WX77GV8TUf $v-DGtOx26<L8R8RVRaRabfhoqsRt  >>r  c                 ,    | j                  d||||      S )ad  
        fetch all unfilled currently open orders

        https://doc.xt.com/#orderopenOrderGet
        https://doc.xt.com/#futures_ordergetOrders
        https://doc.xt.com/#futures_entrustgetPlan
        https://doc.xt.com/#futures_entrustgetProfit

        :param str [symbol]: unified market symbol of the market the orders were made in
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict params: extra parameters specific to the xt api endpoint
        :param bool [params.trigger]: if the order is a trigger order or not
        :param bool [params.stopLossTakeProfit]: if the order is a stop-loss or take-profit order
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        r  r  r  r   r  r  r  s        r  fetch_open_orderszxt.fetch_open_orders  s    " **665%PPr  c                 ,    | j                  d||||      S )ax  
        fetches information on multiple closed orders made by the user

        https://doc.xt.com/#orderhistoryOrderGet
        https://doc.xt.com/#futures_ordergetOrders
        https://doc.xt.com/#futures_entrustgetPlan
        https://doc.xt.com/#futures_entrustgetProfit

        :param str [symbol]: unified market symbol of the market the orders were made in
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict params: extra parameters specific to the xt api endpoint
        :param bool [params.trigger]: if the order is a trigger order or not
        :param bool [params.stopLossTakeProfit]: if the order is a stop-loss or take-profit order
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        rx  r  r  s        r  fetch_closed_orderszxt.fetch_closed_orders)  s    " **8VUE6RRr  c                 ,    | j                  d||||      S )ax  
        fetches information on multiple canceled orders made by the user

        https://doc.xt.com/#orderhistoryOrderGet
        https://doc.xt.com/#futures_ordergetOrders
        https://doc.xt.com/#futures_entrustgetPlan
        https://doc.xt.com/#futures_entrustgetProfit

        :param str [symbol]: unified market symbol of the market the orders were made in
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict params: extra parameters specific to the xt api endpoint
        :param bool [params.trigger]: if the order is a trigger order or not
        :param bool [params.stopLossTakeProfit]: if the order is a stop-loss or take-profit order
        :returns dict: a list of `order structures <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        r{  r  r  s        r  fetch_canceled_orderszxt.fetch_canceled_orders<  s    " **:vueVTTr  c                    | j                          d}|| j                  |      }i }d}d}d}| j                  d||      \  }}| j                  d||      \  }}| j	                  |dd      }	| j                  |d      }
|	r||d<   n|
r||d<   n||d<   |	r]| j                  |ddg      }|d	k(  r"| j                  | j                  ||            }n| j                  | j                  ||            }n|
r[| j                  |d      }|d	k(  r"| j                  | j                  ||            }n| j                  | j                  ||            }ny|d	k(  r"| j                  | j                  ||            }nR|d
k(  s
|dk(  s|dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }|duxs |dk(  xs |dk(  }|r|n| j                  |di       }| j                  ||      S )a  
        cancels an open order

        https://doc.xt.com/#orderorderDel
        https://doc.xt.com/#futures_ordercancel
        https://doc.xt.com/#futures_entrustcancelPlan
        https://doc.xt.com/#futures_entrustcancelProfit

        :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 xt api endpoint
        :param bool [params.trigger]: if the order is a trigger order or not
        :param bool [params.stopLossTakeProfit]: if the order is a stop-loss or take-profit order
        :returns dict: An `order structure <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        NrB   r  r_  r`  ra  rb  r  r   r   r<   r=   r  )r  rH  r  r  rl  r  r  0privateInversePostFutureTradeV1EntrustCancelPlanr  /privateLinearPostFutureTradeV1EntrustCancelPlan6privateInversePostFutureTradeV1EntrustCancelProfitStop5privateLinearPostFutureTradeV1EntrustCancelProfitStop*privateInversePostFutureTradeV1OrderCancel)privateLinearPostFutureTradeV1OrderCancelprivateSpotDeleteOrderOrderIdr@  )r  r-   r   r  rH  r  r  r  r  r  r`  isContractResponser   s                r  cancel_orderzxt.cancel_orderO  s2     	[[(F99-QWXf99-QWX##FIv>!__V5IJ#%GK "$GJ!#GIYYv	6':;F)#PPQUQ\Q\]dflQmnOOPTP[P[\cekPlmYYv';<F)#VVW[WbWbcjlrWstUUVZVaVabikqVrs	!FFt{{SZ\bGcdH!tv~48;KEEdkkRY[aFbcH99$++gv:VWH,  'd2]]DT\L\.DOOHhXZ4[v..r  c                    | j                          i }d}|| j                  |      }|d   |d<   d}d}d}| j                  d||      \  }}| j                  d||      \  }}| j	                  |dd      }| j                  |d      }	|r^| j                  |ddg      }|dk(  r#| j                  | j                  ||            }n| j                  | j                  ||            }n|	r[| j                  |d      }|dk(  r"| j                  | j                  ||            }n| j                  | j                  ||            }n|dk(  r"| j                  | j                  ||            }nt|d	k(  s
|d
k(  s|dk(  r"| j                  | j                  ||            }nCd}
| j                  d|      \  }
}|
dnd}||d<   | j                  | j                  ||            }| j!                  |      gS )a  
        cancel all open orders in a market

        https://doc.xt.com/#orderopenOrderDel
        https://doc.xt.com/#futures_ordercancelBatch
        https://doc.xt.com/#futures_entrustcancelPlanBatch
        https://doc.xt.com/#futures_entrustcancelProfitBatch

        :param str [symbol]: unified market symbol of the market to cancel orders in
        :param dict params: extra parameters specific to the xt api endpoint
        :param bool [params.trigger]: if the order is a trigger order or not
        :param bool [params.stopLossTakeProfit]: if the order is a stop-loss or take-profit order
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        Nr-   r   rA   r  r_  r`  r   r   r<   r=   rT  rS  r  )r  rH  r  r  rl  r  r  3privateInversePostFutureTradeV1EntrustCancelAllPlanr  2privateLinearPostFutureTradeV1EntrustCancelAllPlan9privateInversePostFutureTradeV1EntrustCancelAllProfitStop8privateLinearPostFutureTradeV1EntrustCancelAllProfitStop-privateInversePostFutureTradeV1OrderCancelAll,privateLinearPostFutureTradeV1OrderCancelAllr  privateSpotDeleteOpenOrder
safe_order)r  r   r  r  rH  r  r  r  r  r`  r  r  s               r  cancel_all_orderszxt.cancel_all_orders  s     	[[(F &tGH99:KVU[\f99:KVU[\##FIv>!__V5IJYYv	6':;F)#SSTXT_T_`gioTpqRRSWS^S^_fhnSopYYv';<F)#YYZ^ZeZefmouZvwXXY]YdYdelntYuv	!II$++V]_eJfgH!tv~48;KHHU\^dIefHJ!%!C!CDUW]!^J.8.D'6!4GI66t{{7F7STH* OOH%
 	
r  idsc                    | j                          d|i}d}|| j                  |      }d}| j                  d||      \  }}|t        | j                  dz         | j                  | j                  ||            }| j                  |      gS )a  
        cancel multiple orders

        https://doc.xt.com/#orderbatchOrderDel

        :param str[] ids: order ids
        :param str [symbol]: unified market symbol of the market to cancel orders in
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        orderIdsNrC   zV cancelOrders() does not support swap and future orders, only spot orders are accepted)r  rH  r  r"   r-   privateSpotDeleteBatchOrderr  r  )r  r  r   r  r  rH  r  r  s           r  cancel_orderszxt.cancel_orders  s     	
 [[(F99.&RXYtww  *B   B  C  C33DKK4PQ OOH%
 	
r  c                    | j                  |d      }d|v rd|v xs dnd}| j                  ||d |      }| j                  ||d |      }| j                  |dd      }| j	                  |d      }|dk(  r|n6t        j                  | j                  |      | j                  |d	               }| j	                  |d
      }	|dk(  r|	n6t        j                  | j                  |	      | j                  |d	               }
| j                  |d      }| j                  i d|d| j                  |g d      d| j                  |dd      d|d| j                  |      d|d|d|d| j                  |dd      d| j                  |d      dd d| j                  |dd      d| j	                  |d      d| j	                  |d      d| j	                  |d      d | j	                  |d!      d"||
| j	                  |d#      d | j	                  |d$      | j                  | j                  |d%            | j                  | j                  |d&            | j	                  |d'      d(d d)|      S )*Nr   rJ  r  r   r:   r   createdTimerF  rp  executedQtyupdatedTimer  r-   )r  r  cancelIdra  rb  clientOrderIdclientModifyIdr  r  lastTradeTimestamplastUpdateTimestampr  r  r  postOnlyr  r  rt  r  rK  rL  rM  rN  rO  r  
leavingQtyavgPricerN  r
  r	  r  )filled	remainingrv  r  r  r	  r  )r  r  safe_symbolr  r|  r(   r  r  r  r  r  r{  r  safe_string_lower_2parse_order_statusr  )r  r   rH  r  r  r   r  r  r  filledQuantityr  lastUpdatedTimestamps               r  r@  zxt.parse_order
  s=   ~ ##E84;IU;Rh%'6JY_
!!(FD*E!!(FD*E''v}E	##E95(F29K9KDLaLabjLkmq  nC  nC  DJ  KY  DZ  n[  :\))%?$.&$8w?Q?QRVRgRghvRwy}  zO  zO  PV  We  Pf  zg  @h#00F  
E 
$$$U,fg 
 T//HXY 
 	 

 Y/ 
 !"6 
 "#7 
 f 
 D,,UFKH 
 4++E=A 
  
 D,,UFKH 
 T%%eW5 
 D,,UK@ 
 ((0BC 
  $**52FG! 
" f# 
$ ))%>''z:--d.>.>ug.NO 33D4D4DUM4Z[((6 7 
8 9 	r  c                 H    dddddddddddddd}| j                  |||      S )Nr  rx  r{  rejectedexpired)rw  PARTIALLY_FILLEDrz  r}  REJECTEDEXPIRED
UNFINISHEDrv  
TRIGGERINGry  r|  PLATFORM_REVOCATIONHISTORYr  r  r  statusess      r  r  zxt.parse_order_status  sG     &""  # !)#- 
 &&99r  r  c                 $   | j                          i }d}|| j                  |      }|||d<   |||d<   d}d}d}	| j                  dd|      \  }}| j                  dd|      \  }}|dk(  r"| j	                  | j                  ||            }	nI|dk(  s
|dk(  s|dk(  r"| j                  | j                  ||            }	nt        | j                  d	z         | j                  |	d
i       }
| j                  |
dg       }| j                  ||||      S )a)  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://doc.xt.com/#futures_usergetBalanceBill

        :param str [code]: unified currency code
        :param int [since]: timestamp in ms of the earliest ledger entry
        :param int [limit]: max number of ledger entries to return
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: a `ledger structure <https://docs.ccxt.com/en/latest/manual.html#ledger-structure>`
        Nr  r  rf   r   r   r<   r=   zi fetchLedger() does not support spot transactions, only swap and future wallet transactions are supportedr  r  )r  r  r  r  )privateInverseGetFutureUserV1BalanceBillsr  (privateLinearGetFutureUserV1BalanceBillsr"   r-   r  parse_ledger)r  r  r  r  r  r  r  r  r  r  r  ledgers               r  fetch_ledgerzxt.fetch_ledger  sB    	}}T*H#(GK $GG99-vVf99-vViEEdkkRY[aFbcH!tv~48;KDDT[[QXZ`EabHtww  *U   U  V  V0 x26w3  5%@@r  c                    | j                  |d      }|dk(  rdnd}| j                  |d      }| j                  ||      }| j                  |d      }| j                  || j                  |d      |d d d | j	                  | j                  |d            | j                  ||      | j                  |d	      || j                  |      d | j                  |d
      d d d dd|      S )Nr  ADDinoutr!  r  r-   r  r  afterAmountr  )r  r-   	directionr-  referenceIdreferenceAccountr  r  r  r  r  beforeafterr  r	  )r  safe_currencyr  safe_ledger_entryparse_ledger_entry_typer  r|  r  )r  itemr  r  r  r%  r  s          r  parse_ledger_entryzxt.parse_ledger_entry  s     f-!U]D	%%dF3
%%j(;%%dM:	%%""4." $001A1A$1OP//
HE&&tX6"Y/%%dM: '
& ' 	r  c           	      >    ddddddddd}| j                  |||      S )Nr   r   r	  zauto-deleveraging)EXCHANGECLOSE_POSITION	TAKE_OVERMERGEQIANG_PING_MANAGERFUNDFEEADLr  )r  r  
ledgerTypes      r  r  zxt.parse_ledger_entry_type%  s8    "% "'&	

 
D$77r  c                 V   | j                          d}| j                  |      \  }}| j                  |      }| j                  ||      }| j	                  d|d       |d   |d}| j                  | j                  ||            }| j                  |di       }| j                  ||      S )a  
        fetch the deposit address for a currency associated with self account

        https://doc.xt.com/#deposit_withdrawaldepositAddressGet

        :param str code: unified currency code
        :param dict params: extra parameters specific to the xt api endpoint
        :param str params['network']: required network id
        :returns dict: an `address structure <https://docs.ccxt.com/en/latest/manual.html#address-structure>`
        NrW   r  r-   )r  r  r  )	r  handle_network_code_and_paramsr  network_code_to_idcheck_required_argumentprivateSpotGetDepositAddressr  r  parse_deposit_address)	r  r  r  networkCoder  r-  r  r  r  s	            r  fetch_deposit_addresszxt.fetch_deposit_address2  s     	"AA&IV==&++K>	$$%:IyQ 
 44T[[&5QR 8R8))&(;;r  c                     | j                  |d      }| j                  |       || j                  d |      d || j                  |d      dS )Naddressmemo)r  r  r  r  tag)r  check_addressr  )r  depositAddressr  r  s       r  r  zxt.parse_deposit_addressV  sW     "">9=7#"//h?##NF;
 	
r  c                 4   | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }| j	                  |di       }| j	                  |dg       }	| j                  |	||||      S )a  
        fetch all deposits made to an account

        https://doc.xt.com/#deposit_withdrawalhistoryDepositGet

        :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 transaction structures to retrieve
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/en/latest/manual.html#transaction-structure>`
        Nr-   r  r  r  r  r  )r  r  privateSpotGetDepositHistoryr  r  parse_transactions)
r  r  r  r  r  r  r  r  r  depositss
             r  fetch_depositszxt.fetch_depositsg  s     	}}T*H"*4.GJ#(GK $GG44T[[&5QR6 x26??4"5&&x5%PPr  c                 4   | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }| j	                  |di       }| j	                  |dg       }	| j                  |	||||      S )a  
        fetch all withdrawals made from an account

        https://doc.xt.com/#deposit_withdrawalwithdrawHistory

        :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 transaction structures to retrieve
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/en/latest/manual.html#transaction-structure>`
        Nr-   r  r  r  r  r  )r  r  privateSpotGetWithdrawHistoryr  r  r  )
r  r  r  r  r  r  r  r  r  withdrawalss
             r  fetch_withdrawalszxt.fetch_withdrawals  s     	}}T*H"*4.GJ#(GK $GG55dkk'66RS6 x26oodGR8&&{HeUFSSr  r  c                    | j                  |       | j                          | j                  |      }| j                  ||      \  }}d}| j	                  |      \  }}| j                  | j                  di       }| j                  ||||      }	|d   |	| j                  ||      |d}
|||
d<   | j                  | j                  |
|            }| j                  |di       }| j                  ||      S )a  
        make a withdrawal

        https://doc.xt.com/#deposit_withdrawalwithdraw

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str [tag]:
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/en/latest/manual.html#transaction-structure>`
        Nr  r-   )r  r  r  r  r  r  )r  r  r  handle_withdraw_tag_and_paramsr  r  rR  r{  currency_to_precisionprivateSpotPostWithdrawr  parse_transaction)r  r  r  r  r  r  r  r  networkIdsByCodesr-  r  r  r  s                r  r   zxt.withdraw  s     	7#==&99#vFV"AA&IV OODLL*bI&&'8+tTR	 00v>	
 ?!GFO//GV0LM 8R8%%fh77r  transactionr  c                    d|v rdnd}| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  |d      |      }| j                  |d      }||nd }	| j                  |d	      }
i d
|d| j                  |d      d| j                  |d      d|d| j	                  |      dd d| j                  |d      d|d|dd dd d|d|d| j                  |d      d|d| j                  |
|      d| j                  | j                  |d            ||	|d dd dS )NfromAddrr  r   r  r  r  r  r	  r  r  r-   txidtransactionIdr  r  updatedaddressFrom	addressTotagFromtagTor  r  r  r  r  )r  rv  rate)commentr	  internal)r  r  r  r|  r  r  parse_transaction_status)r  r  r  r  r  r  r  currencyCoder	  r
  r-  s              r  r  zxt.parse_transaction  s   P (;6yZ%%k=A	"";	:V4..t/?/?Z/XZbc{E2'*lT$$[':	
K
$"";5
 D$$[/B
 	

 Y/
 t
 4++KD
 
 w
 t
 T
 4
 D
 d&&{H=
 
  t..y,G!
" d33D4D4D[RZ4[\#
$ '
 1
 	
r  c                 <    dddddddd}| j                  |||      S )Npendingr{  failedok)SUBMITREVIEWAUDITEDPENDINGCANCELFAILSUCCESSr  r  s      r  r  zxt.parse_transaction_statusG  s5       
 &&99r  rX  c                 "   |t        | j                  dz         | j                  |d      }| j                  d|dddg       |dk  s|dkD  rt	        | j                  d	z         | j                          | j                  |      }|d
   st        | j                  dz         |d   ||d}d}| j                  d||      \  }}d}|dk(  r#| j                  | j                  ||            }|S | j                  | j                  ||            }|S )a  
        set the level of leverage for a market

        https://doc.xt.com/#futures_useradjustLeverage

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict params: extra parameters specific to the xt api endpoint
        :param str params['positionSide']: 'LONG' or 'SHORT'
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentrJ  r   rI  rH  r   }   z3 setLeverage() leverage should be between 1 and 125r   z- setLeverage() supports contract markets onlyr-   )r   rJ  rX  r   )r   r-   r  r  r   r  rH  r   r  4privateInversePostFutureUserV1PositionAdjustLeverager  3privateLinearPostFutureUserV1PositionAdjustLeverage)	r  rX  r   r  rJ  rH  r  r  r  s	            r  set_leveragezxt.set_leverageS  s5    >#DGG.Y$YZZ''?$$]L.SY[bRcdqLhnTWW'\\]]V$z"DGG&UUVVTl( 

 99-QWXiPPQUQ\Q\]dflQmnH  OOPTP[P[\cekPlmH r  c                 *    | j                  ||d|      S )a  
        add margin to a position

        https://doc.xt.com/#futures_useradjustMargin

        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict params: extra parameters specific to the xt api endpoint
        :param str params['positionSide']: 'LONG' or 'SHORT'
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        r  modify_margin_helperr  r   r  r  s       r  
add_marginzxt.add_margin       ((GGr  c                 *    | j                  ||d|      S )a  
        remove margin from a position

        https://doc.xt.com/#futures_useradjustMargin

        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict params: extra parameters specific to the xt api endpoint
        :param str params['positionSide']: 'LONG' or 'SHORT'
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        SUBr%  r'  s       r  reduce_marginzxt.reduce_margin  r)  r  c                    | j                  |d      }| j                  d|dddg       | j                          | j                  |      }|d   |||d}d }| j	                  d||      \  }}d }	|dk(  r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j                  |	|      S )	NrJ  r   rI  rH  r-   )r   r;   r  rJ  modifyMarginHelperr   )	r  r  r  rH  r  ,privateInversePostFutureUserV1PositionMarginr  +privateLinearPostFutureUserV1PositionMarginparse_margin_modification)
r  r   r  addOrReducer  rJ  rH  r  r  r  s
             r  r&  zxt.modify_margin_helper  s    ''?$$]L.SY[bRcdV$Tl(	
 99:NPVX^_iHHU\^dIefHGGT[]cHdeH --h??r  c                 <    |d d d | j                  d |      d d d d d d
S )N)
r  r  r  r  r   r  r  r,  r  r  )r  )r  r  rH  s      r  r1  zxt.parse_margin_modification  s7    &&tV4
 	
r  c                    | j                          d}| j                  dd|      \  }}d}|dk(  r| j                  |      }n| j                  |      }| j	                  |dg       }| j                  |      }| j                  ||d      S )a  
        retrieve information on the maximum leverage for different trade sizes

        https://doc.xt.com/#futures_quotesgetLeverageBrackets

        :param str [symbols]: a list of unified market symbols
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
        Nri   r   r  r   )r  r  7publicInverseGetFutureMarketV1PublicLeverageBracketList6publicLinearGetFutureMarketV1PublicLeverageBracketListr  r  parse_leverage_tiers)r  r>  r  r  r  r  s         r  fetch_leverage_tierszxt.fetch_leverage_tiers  s     	99:NPTV\]iSSTZ[HRRSYZH2 x26%%g.((wAAr  c                 >   i }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d dd      }| j	                  ||      }	|)| j                  |	|      sU| j                  ||      ||	<   k| j                  ||   |      ||	<    |S )Nr   r   r  r   )r  r  r  r  r  in_arrayparse_market_leverage_tiers)
r  r  r>  marketIdKeyr  r#  r$  r  rH  r   s
             r  r7  zxt.parse_leverage_tiers  s    $ q#h-( 		WAQKE''x8H%%hc:FF%%h7F"==1%)%E%EeV%TF6N!%!A!A(1+v!Vv		W r  c                 `   | j                          | j                  |      }d|d   i}d}| j                  d||      \  }}d}|dk(  r"| j                  | j	                  ||            }n!| j                  | j	                  ||            }| j                  |di       }| j                  ||      S )a  
        retrieve information on the maximum leverage for different trade sizes of a single market

        https://doc.xt.com/#futures_quotesgetLeverageBracket

        :param str symbol: unified market symbol
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: a `leverage tiers structure <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
        r   r-   Nrj   r   r  )r  rH  r  9publicInverseGetFutureMarketV1PublicLeverageBracketDetailr  8publicLinearGetFutureMarketV1PublicLeverageBracketDetailr  r;  )r  r   r  rH  r  r  r  r  s           r  fetch_market_leverage_tierszxt.fetch_market_leverage_tiers  s     	V$fTl
 99:TV\^deiUUVZVaVabikqVrsHTTUYU`U`ahjpUqrH. x26//f==r  c                    g }| j                  |dg       }t        dt        |            D ]  }||   }| j                  |d      }| j	                  ||dd      }|j                  | j                  |d      | j                  ||dd      |d   | j                  ||dz
     d	d      | j                  |d	      | j                  |d
      | j                  |d      |d        |S )NleverageBracketsr   r   r  r   bracketrj  r   maxNominalValuemaintMarginRatemaxLeverage)tierr   r  r`  ra  maintenanceMarginRaterF  r  )	r  r  r  r  r  rF  r  r  r|  )r  r  rH  r   bracketsr#  rG  r  s           r  r;  zxt.parse_market_leverage_tiersA  s    $ ??4);R@q#h-( 	AA;D''h7H%%hZHFLL))$	:**8VS*M"8,#//QARTUV#//6GH)-)9)9$@Q)R#//mD	 			 r  c           
      J   |t        | j                  dz         | j                          | j                  |      }|d   st	        | j                  dz         d|d   i}|||d<   d}| j                  d||      \  }}d}|d	k(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |d
i       }	| j                  |	dg       }
g }t        dt        |
            D ]s  }|
|   }| j                  |d      }| j                  ||      }| j                  |d      }|j                  ||| j!                  |d      || j#                  |      d       u | j%                  |d      }| j'                  ||d   ||      S )aR  
        fetches historical funding rates

        https://doc.xt.com/#futures_quotesgetFundingRateRecord

        :param str [symbol]: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of [funding rate structures] to fetch
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/en/latest/manual.html?#funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentr<   z7 fetchFundingRateHistory() supports swap contracts onlyr   r-   r  rb   r   r  r  r   r  fundingRate)r  r   rK  r  r  r  )r   r-   r  rH  r   r  6publicInverseGetFutureMarketV1PublicQFundingRateRecordr  5publicLinearGetFutureMarketV1PublicQFundingRateRecordr  r  r  r  r  r  rF  r|  r  sort_byfilter_by_symbol_since_limit)r  r   r  r  r  rH  r  r  r  r  r  ratesr#  r$  r  symbolInnerr  sorteds                     r  fetch_funding_rate_historyzxt.fetch_funding_rate_historye  s    >#DGG.e$effV$f~DGG&__``fTl
 $GG99:SU[]cdiRRSWS^S^_fhnSopHQQRVR]R]^egmRnoH* 8R84q#e*% 	A!HE''x8H**8V<K))%?ILL%#//}E& LL3 	 e[1009I5RWXXr  c                 &    | j                  ||      S )aa  
        fetch the current funding rate interval

        https://doc.xt.com/#futures_quotesgetFundingRate

        :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>`
        )fetch_funding_rate)r  r   r  s      r  fetch_funding_intervalzxt.fetch_funding_interval  s     &&vv66r  c                    | j                          | j                  |      }|d   st        | j                  dz         d|d   i}d}| j	                  d||      \  }}d}|dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |di       }| j                  ||      S )	aP  
        fetch the current funding rate

        https://doc.xt.com/#futures_quotesgetFundingRate

        :param str symbol: unified market symbol
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r<   z0 fetchFundingRate() supports swap contracts onlyr   r-   Nra   r   r  )
r  rH  r   r-   r  0publicInverseGetFutureMarketV1PublicQFundingRater  /publicLinearGetFutureMarketV1PublicQFundingRater  parse_funding_rate)r  r   r  rH  r  r  r  r  s           r  rU  zxt.fetch_funding_rate  s     	V$f~DGG&XXYYfTl
 99:LfV\]iLLT[[Y`bhMijHKKDKKX_agLhiH 8R8&&vv66r  c                 T   | j                  |d      }| j                  ||dd      }| j                  |d      }| j                  |d      }||dz   }i d|d|dd d	d d
d dd dd dd d| j                  |d      d|d| j	                  |      dd dd dd dd dd dd d|iS )Nr   r  r<   nextCollectionTimecollectionInternalr  r  	markPrice
indexPriceinterestRateestimatedSettlePricer  r  rK  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )r  r  r  r|  r  )r  r   rH  r  r   r  r  s          r  rZ  zxt.parse_funding_rate  sU    ##Hh7!!(FC@%%h0DE	##H.BC#~H
H
f
 
 $	

 D
 #D
 
 
 4++HmD
 	
 t||I6
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                    | j                          | j                  |      }|d   st        | j                  dz         d|d   i}|||d<   |||d<   d}| j	                  d||      \  }}d}|d	k(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |d
i       }	| j                  |	dg       }
g }t        dt        |
            D ](  }|
|   }|j                  | j                  ||             * | j                  |d      }| j                  |||      S )a  
        fetch the funding history

        https://doc.xt.com/#futures_usergetFunding

        :param str symbol: unified market symbol
        :param int [since]: the starting timestamp in milliseconds
        :param int [limit]: the number of entries to return
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict[]: a list of `funding history structures <https://docs.ccxt.com/#/?id=funding-history-structure>`
        r<   z3 fetchFundingHistory() supports swap contracts onlyr   r-   Nr  r  r^   r   r  r  r   r  )r  rH  r   r-   r  3privateInverseGetFutureUserV1BalanceFundingRateListr  2privateLinearGetFutureUserV1BalanceFundingRateListr  r  r  rF  parse_funding_historyrN  filter_by_since_limit)r  r   r  r  r  rH  r  r  r  r  r  r  r#  r$  rR  s                  r  fetch_funding_historyzxt.fetch_funding_history  sf    	V$f~DGG&[[\\fTl
 #(GK $GG99:OQWY_`iOOPTP[P[\cekPlmHNNt{{[bdjOklH, x26gr2q#e*% 	EA!HEMM$44UFCD	E fk2))&%??r  c           
      *   | j                  |d      }| j                  ||dd      }| j                  |d      }| j                  |      }| j                  |d      }||||| j	                  |      | j                  |d      | j                  |d      dS )	Nr   r  r<   r!  r  r-   cast)r  r   r  r  r  r-   r  )r  r  r  r  r  r|  )r  r   rH  r  r   r%  r  r  s           r  rm  zxt.parse_funding_history=  s     ##Hh7!!(FC@%%h7
&&z2%%h>	"Y/""8T2&&x8
 	
r  c                    | j                          | j                  |      }d|d   i}d}| j                  d||      \  }}d}|dk(  r"| j                  | j	                  ||            }n!| j                  | j	                  ||            }| j                  |dg       }t        dt        |            D ]X  }||   }	| j                  |	d      }
| j                  |
ddd      }| j                  |	d	      }|d
k7  sF| j                  |	|      c S  y)a~  
        fetch data on a single open contract trade position

        https://doc.xt.com/#futures_usergetPosition

        :param str symbol: unified market symbol of the market the position is held in
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        r   r-   Nrx   r   r  r   r   positionSizer   )r  rH  r  )privateInverseGetFutureUserV1PositionListr  (privateLinearGetFutureUserV1PositionListr  r  r  r  r  parse_position)r  r   r  rH  r  r  r  	positionsr#  r$  r  marketInnerrs  s                r  fetch_positionzxt.fetch_positionW  s&    	V$fTl
 99/6SYZiEEdkkRY[aFbcHDDT[[QXZ`EabH4 OOHh;	q#i.) 	?AaLE''x8H**8T4LK++E>BLs"**5+>>	? r  c                    | j                          d}| j                  dd|      \  }}d}|dk(  r| j                  |      }n| j                  |      }| j	                  |dg       }g }t        dt        |            D ]N  }||   }| j                  |d      }	| j                  |	ddd      }
|j                  | j                  ||
             P | j                  |d|d      S )	aj  
        fetch all open positions

        https://doc.xt.com/#futures_usergetPosition

        :param str [symbols]: list of unified market symbols, not supported with xt
        :param dict params: extra parameters specific to the xt api endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nry   r   r  r   r   r   F)r  r  rt  ru  r  r  r  r  r  rF  rv  filter_by_array_positions)r  r>  r  r  r  rw  r  r#  r$  r  rx  s              r  fetch_positionszxt.fetch_positions  s     	99:JDRXYiEEfMHDDVLH4 OOHh;	q#i.) 	CAaLE''x8H**8T4LKMM$--e[AB		C
 --fhOOr  c           
         | j                  |d      }| j                  ||d d      }| j                  ||d d      }| j                  |d      }|dk(  rdnd}| j                  |d      }| j	                  i d|d	d d|d
d dd dd d| j                  |d      d| j                  |d      d|d   d| j                  |d      dd dd d| j                  |d      d|d|dd dd d d d |d d d      S )Nr   r   positionTypeCROSSEDcrossisolatedr(  r  r-   r  r  r  r  rJ  	contractsrs  rp  
entryPricer^  notionalrX  
collateralinitialMarginmaintenanceMargininitialMarginPercentage)maintenanceMarginPercentageunrealizedPnlliquidationPricer  r   marginRatio)r  r  r  r|  safe_positionr  r  )r  positionrH  r  r   r~  r  r  s           r  rv  zxt.parse_position  s   & ##Hh7!!(FD*E!!(FD*E''.A!-!:W
%%h0@A
!! #
H#
$#
 f#
 	#

 #
 d#
 D**8^D#
 ))(NC#
 F>2#
 $**8\B#
 #
 #
 ))(J?#
 *#
 Z#
   !#
" &t##
$ ,0! $$/#
  	r  fromAccount	toAccountc                    | j                          | j                  |      }| j                  | j                  d      }| j	                  |||      }| j	                  |||      }	| j                  ||      }
| j                         |d   |
||	d}| j                  | j                  ||            }| j                  ||      S )aH  
        transfer currency internally between wallets on the same account

        https://doc.xt.com/#transfersubTransferPost

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from -  spot, swap, leverage, finance
        :param str toAccount: account to transfer to - spot, swap, leverage, finance
        :param dict params: extra parameters specific to the whitebit api endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r  r-   )bizIdr  r  fromto)
r  r  r  rR  r  r  uuidprivateSpotPostBalanceTransferr  parse_transfer)r  r  r  r  r  r  r  accountsByTypefromAccountIdtoAccountIdrA  r  r  s                r  r   zxt.transfer  s     	==&~F((kR&&~y)L11$?YY[ "!
 66t{{7F7ST ""8X66r  c           
      :    || j                  |d      d d d d d d d d	S )Nr  )	r  r-   r  r  r  r  r  r  r  r  )r  r   r  s      r  r  zxt.parse_transfer!  s4    ""8X6

 
	
r  r  c                    |t        | j                  dz         | j                          | j                  |      }|d   rt	        | j                  dz         |j                         }|dk7  r|dk7  rt        | j                  dz         |dk(  rd}nd}| j                  |d	      }|t        | j                  d
z         |||d   d}| j                  | j                  ||            }|S )a  
        set margin mode to 'cross' or 'isolated'

        https://doc.xt.com/#futures_userchangePositionType

        :param str marginMode: 'cross' or 'isolated'
        :param str [symbol]: required
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.positionSide]: *required* "long" or "short"
        :returns dict: response from the exchange
        z+ setMarginMode() requires a symbol argumentr:   z/ setMarginMode() supports contract markets onlyr  r  z@ setMarginMode() marginMode argument should be isolated or crossr  ISOLATEDrJ  zL setMarginMode() requires a positionSide parameter, either "LONG" or "SHORT"r-   )r~  rJ  r   )
r   r-   r  rH  r   lowerr   r;  /privateLinearPostFutureUserV1PositionChangeTyper  )r  r  r   r  rH  posSider  r  s           r  set_margin_modezxt.set_margin_mode.  s     >#DGG.[$[\\V$&>DGG&WWXX%%'
#
g(=TWW'iijj "J#J((@?#DGG.|$|}}&#Tl

 GGT[]cHde r  c                    |t        | j                  dz         | j                          | j                  |      }i }	| j	                  |dd      }
| j	                  |dd      }| j                  |ddg      }|
du}|du}|s|r||	d<   n||	d<   | j                  ||      |	d	<   d}|d
   r|r| j                  ||
      |	d<   n-|| j                  ||      |	d<   n| j                  ||      |	d<   d}| j                  d||      \  }}|dk(  rH|s|r"| j                  | j                  |	|            }n| j                  | j                  |	|            }n~|s|r"| j                  | j                  |	|            }nX| j                  | j                  |	|            }n6| j                  ||      |	d<   | j                  | j                  |	|            }|d
   r|n| j                  |di       }| j!                  ||      S )a  
        cancels an order and places a new order

        https://doc.xt.com/#orderorderUpdate
        https://doc.xt.com/#futures_orderupdate
        https://doc.xt.com/#futures_entrustupdateProfit

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of the currency you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.stopLoss]: price to set a stop-loss on an open position
        :param float [params.takeProfit]: price to set a take-profit on an open position
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( editOrder() requires an amount argumentrL  rM  rN  rO  rb  r  rt  r<   rF  rJ   r   r  r  )r   r-   r  rH  r  r  r=  r>  r  6privateInversePostFutureTradeV1EntrustUpdateProfitStopr  *privateInversePostFutureTradeV1OrderUpdate5privateLinearPostFutureTradeV1EntrustUpdateProfitStop)privateLinearPostFutureTradeV1OrderUpdateprivateSpotPutOrderOrderId	safe_dictr@  )r  r-   r   r  r  r  rt  r  rH  r  rL  rN  r\  r]  r  r  r  s                    r  
edit_orderzxt.edit_order]  s-   & >#DGG.X$XYYV$%%fj:LM''>RS
6J#=>d*
"$."$GJ!#GI#66vuEGG&>.2.E.Efh.W*+'040G0GPZ0[,-%)%=%=ff%M	"G"==k6SYZOGV)##ZZ[_[f[fgnpv[wxH#NNt{{[bdjOklH #YYZ^ZeZefmouZvwH#MMdkkZaciNjkH #'":":66"JGJ66t{{7F7STH %Vn4>>(HVX3Y//r  c
                    | j                  |dd      }
|
|
dk7  r| j                  dz   |z   }| j                  |di       }| j                  |d      }| j                  |d|      }| j                  |d      }| j                  |d|      }| j	                  | j
                  d   ||       | j                  | j
                  d	   ||       t        |      y )
NmsgInfomcr   errorr  msgrA  rB  )safe_string_upper_2r-   r  r  throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r  r  reasonurlmethodheadersbodyr  requestHeadersrequestBodyr  feedbackr  spotErrorCode	errorCodespotMessagemessages                    r  handle_errorszxt.handle_errors  s    j ))(ItD&I"5ww}t+HOOHgr:E ,,Xt<M((FI**8Y?K&&ue[AG001I9V^_001I7T\]))r  GETc                    |d   dk(  }|d   }d| j                  ||      z   }	d }
|dk(  s|dk(  r+|rd| j                  z   |	z   }
nd| j                  z   dz   |	z   }
n|	}
| j                  d   |   |
z   }| j                  || j	                  |            }| j                  | j                  |            }d	d
i}|r| j                          | j                  | j                  d      }| j                  |d|      }| j                  | j                               }|}|
dk(  s|
dk(  s|
dk(  s
|
dk(  s|
dk(  r!d}|
j                  d      dkD  r||d<   n||d<   |dk(  xs |dk(  xs |dk(  }|dk(  r|dk(  rd}|rd n| j                  |      }d }|dk(  s|dk(  rd| j                  z   dz   |z   dz   dz   |z   }|rL|r;|d|z   z  }|d |z   d z   |
z   d z   | j                  | j                  |            z   z  }n#|d |z   d z   |
z   z  }n|d |z   d z   |
z   d z   |z   z  }d!|d"<   ||d#<   nMd$| j                  z   dz   dz   |z   }|dk(  r"|r|d|z   z  }|d |
z   d z   |z   z  }n|d |
z   z  }n|d |
z   d z   |z   z  }| j!                  | j#                  |      | j#                  | j$                        t&        j(                        }| j                  |d%<   ||d&<   ||d'<   n
|r|d|z   z  }||||d(S ))Nr   r   r   rO  r:   r   z/publicr   zContent-Typezapplication/jsonr  z	/v4/orderz/future/trade/v1/order/createz$/future/trade/v1/entrust/create-planz&/future/trade/v1/entrust/create-profitz#/future/trade/v1/order/create-batchCCXTr=   clientMediamediar  r   r   PUTFz5xt-validate-algorithms=HmacSHA256&xt-validate-appkey=z&xt-validate-recvwindow=z&xt-validate-tz	imestamp=?#
HmacSHA256zxt-validate-algorithmszxt-validate-recvwindowzxt-validate-appkey=zxt-validate-appkeyzxt-validate-timestampzxt-validate-signature)r  r  r  r  )implode_paramsr4   r   r  extract_params	urlencodekeysortcheck_required_credentialsr  rR  r  r  findjsonapiKey	rawencodehmacencodesecrethashlibsha256)r  pathr   r  r  r  r  signedendpointr  payloadr  query
urlencodeddefaultRecvWindowr  r  r-   isUndefinedBodypayloadString	signatures                        r  signzxt.sign  s   Q9$q6++D&99H$6,w6,y87BGiix(72		&$"5"5d";<^^DLL$78
.
 ++- $ 0 0| L))%?PQJ--djjl;ID;&G7V,V\c  hN  ]N  T[  _G  TG  MT  X}  M}<<)B.*,D'$&DM &%gT=N5NgTX\fTfO%h&&8"'*4		$D MF"F(: WZ^ZeZe e  iC  !C  FP  !P  Sc  !c  fq  !q  t}  !}"!sZ//%v);g)E)Kdnn]a]i]ijo]pNq)qq%v);g)EE!S6\C%7'%AC%G$%NNM4@014>01 5 CFV VYd dgp pU?!sZ//%w)<z)II%w6!S7]S%84%??M		$++m"<dkk$++>VX_XfXfgI,0KKG()/8G+,/8G+,sZ''fdwOOr  )N)NN)c__name__
__module____qualname__r   r  r  r	   r  r   r2  r   r   r<  r5  r6  r@  dictrG  strr  listr  r  r  r   r  r  r  r  r  r  r  r  floatr3  r   r   r   r2  r5  r6  rj  rt  r  r  r  r  r  r  r   r  r@  r  r   r
   r  r  r  r   r  r  r  r  r   r   r   r  r  r#  r(  r,  r   r&  r1  r   r8  r7  r   r@  r;  rS  r   rV  rU  rZ  ro  rm  ry  r   r|  rv  r   r   r  r  r  r  r  __classcell__)r  s   @r  r*   r*      s5   Q# QfD !# 5s 5. ') ZZ Zx $& D$v, D* )+ 8+t 46 A8Fs4 sF sj 26DW[df UJ# UJc UJQT UJn$
 $
4 $
L :>b Us U3 Un 02 H13 H1T 26b R?T#Y R?W R?h 48 '4tCy '4RN` 6:UW C13 C1s C1# C1J -1tRV_a e?c e? e?C e?NbH $& I,V+)Z RT K K5 K" gksu Y3 Yi Yy YRW Y`c Y@ HLTV 4/ 4/l LPXZ @2C @2D 26b j/c j/3 j/X *.Dt\^ _?3 _?c _? _?B <@daenp w?S w? w?[^ w?r /3TXac Q Q3 Qc Q& 154VZce S# SS SPS S& 37TX\eg UC Us URU U& 37r K/s K/C K/Z /32 G
 G
R ;?r #
c #
C #
dSXk #
JeN:$ (,$TZ\ 9A 9AC 9As 9Aaefqar 9Av% %N8 79 "<# "<^ "<H
n 
" *.Dt\^ 3Q3 3Qc 3Q 3Qj -1tRV_a 3Tc 3T 3TC 3Tj DHPR )8S )8% )8# )8Wb )8VI
T I
X I
Q\ I
V
: 9=R *S *# *X =? H He H @B HC H H MO @3 @Se @8
>P 
 9=R ,BDI ,BM ,B\P] > ?A -># ->T,EW ->^"\@R "H 8<$]ajl BY BYC BYWZ BYH :< 
7S 
7 
7 68 &7 &7K &7P"
; "
H 37TX\eg :@C :@s :@RU :@x
4 24 7S 7r 48 2PtCy 2PtH~ 2Ph1f [] (7S (7% (7c (7c (7an (7T
 >B" -# -s -^ `drv  @B V0S V0# V0Y V0i V0Y\ V0lo V0  GL V0p@D  b$T @Pr  r*   )/ccxt.base.exchanger   ccxt.abstract.xtr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   ccxt.base.decimal_to_precisionr'   ccxt.base.preciser(   r*    r  r  <module>r     sx    ( (  t  t  t  t  t  t  * 0 - . ' & . ) ) ) . * + 4 %[LP; [LPr  