
    eiO                    \   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.dS )    )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defdZdad
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dad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dad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d0Z0di fd1e
e         dede
e1         fd2Z2dad3Z3d4 Z4dddi fd5e5dedede
e6         fd6Z7dade6fd7Z8d8 Z9i fd5ede:fd9Z;dade:fd:Z<dddi fd5e5dedefd;Z=dddi fd5e5dedefd<Z>di fd5ed#e!d=ed>e5de?f
d?Z@dad@edAeAde?fdBZBdC ZCdi fdDeDdefdEZEi fded#e!fdFZFi fded#e!fdGZGi fdedeHfdHZIdadeHfdIZJdi fde
e         deKfdJZLdbdeKfdKZMi fdede
eN         fdLZOdade
eN         fdMZPdddi fdededefdNZQi fdedeRfdOZSi fdedeRfdPZTdadeRfdQZUdddi fde5dedefdRZVdadSZWi fdefdTZXdi fde
e         de
eY         fdUZZdadVZ[i fd5ed#e!dWedXede\f
dYZ]dadZZ^di fd[ede5fd\Z_ddi fd(eded!e#d"e$d#e%d$e%de1fd]Z`d^ Zag d_i ddfd`Zb xZcS )cxtreturnc                 *$   |                      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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|                     d          |                     d          |                     d          |                     d          g|                     d          |                     d¦          g|                     dæ          |                     dĦ          g|                     dŦ          |                     dƦ          g|                     dǦ          |                     dȦ          g|                     dɦ          |                     dʦ          g|                     d˦          |                     d̦          g|                     dͦ          |                     dΦ          g|                     dϦ          |                     dЦ          g|                     dѦ          |                     dҦ          g|                     dӦ          |                     dԦ          g|                     dզ          |                     d֦          g|                     dצ          |                     dئ          gg|                     d          |                     d          g|                     d          |                     d¦          g|                     dæ          |                     dĦ          g|                     dŦ          |                     dƦ          g|                     dǦ          |                     dȦ          g|                     dɦ          |                     dʦ          g|                     d˦          |                     d̦          g|                     dͦ          |                     dΦ          g|                     dϦ          |                     dЦ          g|                     dѦ          |                     dҦ          g|                     dӦ          |                     dԦ          g|                     dզ          |                     d֦          g|                     dצ          |                     dئ          ggdٜdڜdd|                     dԦ          |                     dЦ          |                     d          |                     dԦ          g|                     dۦ          |                     dܦ          g|                     dݦ          |                     dަ          g|                     dߦ          |                     d          g|                     d          |                     d          g|                     dզ          |                     d          g|                     dצ          |                     d          g|                     d          |                     dئ          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg|                     d          |                     dЦ          g|                     dۦ          |                     d          g|                     dݦ          |                     d          g|                     dߦ          |                     d          g|                     d          |                     d          g|                     dզ          |                     d          g|                     dצ          |                     d          g|                     d          |                     d          g|                     d          |                     dަ          g|                     d          |                     d          g|                     d          |                     d֦          ggdٜdڜd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fetchAllGreeksfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesPerSymbolfetchCanceledOrdersfetchClosedOrdersfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawalsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchL3OrderBookfetchLedgerfetchLedgerEntryfetchLeveragefetchLeverageTiersfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrdersByStatusfetchOrderTradesfetchPositionfetchPositionsfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchVolatilityHistory)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)rI  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  rU  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trailingr]  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   createOrdersro   rv   rs   ry   rU   rp   extendsdefault)lastmarkindex)r  r  r  r  )r  r  )r  rG   ro   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    E/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/xt.pyr  zxt.describe   s"   b$ 8 8 : : U=
$U=
DU=
 $U=
 U=
 tU=
 U=
 4U=
  bbb $b 	b
 $b %b Tb b "4b tb b 'b /b 0b tb  &u!b" (#b b$ T%b&  'b( !%)b* +b,  -b. &u/b0 "51b2 +E3b4 )%5b6 ,U7b8 &t9b: $T;b< "4=b> ?b@ &tAbB (CbD 1%Eb b bF  GbH *5IbJ *5KbL +EMbN &tObP 'QbR (SbT #DUbV *4WbX $UYbZ u[b\ "5]b^ #E_b` tabb #Ecbd  ebf %dgb b bh +Dibj kbl !%mbn  obp dqbr $Usbt +Eubv "4wbx uybz #E{b| d}b~ !$b@ "5AbB tCbD &tEbF #EGbH  Ib b bJ !$KbL )%MbN )%ObP uQbR tSbT UbV TWbX tYbZ "5[b\ #E]b^ %e_b` &uabb 'cbd $Uebf  gbh !%ibj )%kb bl $)$(,1 $$#"!%#(  Cb b bU=
^ Y_U=
` 1340	  (Q)6 5 aU=
@  *+%'%&&'&'+,,-*+$%-.,-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 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 FGJ JAU=
V
 !%"&!..w77!..w77 "..s33T5F5Fw5O5OP!..v668I8I(8S8ST!..w779J9J89T9TU!..w779J9J89T9TU!..w779J9J89T9TU!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..z::D<M<Mh<W<WX"  "..s33T5F5Fw5O5OP!..v668I8I(8S8ST!..w779J9J89T9TU!..w779J9J89T9TU!..w779J9J89T9TU!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..z::D<M<Mh<W<WX"! % %N "&"&!..x88!..x88 "..s33T5F5Fx5P5PQ!..x88$:K:KI:V:VW!..y994;L;LY;W;WX!..y994;L;LY;W;WX!..z::D<M<Mi<X<XY!..z::D<M<Mi<X<XY!..z::D<M<Mi<X<XY!..z::D<M<Mh<W<WX!..{;;T=N=Ny=Y=YZ!..{;;T=N=Ny=Y=YZ!..{;;T=N=Ny=Y=YZ" "..s33T5F5Fx5P5PQ!..x88$:K:KJ:W:WX!..y994;L;LY;W;WX!..y994;L;LY;W;WX!..z::D<M<Mi<X<XY!..z::D<M<Mi<X<XY!..z::D<M<Mi<X<XY!..z::D<M<Mi<X<XY!..{;;T=N=Ny=Y=YZ!..{;;T=N=Ny=Y=YZ!..{;;T=N=Nx=X=XY" ! !OI IW
U=
j 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 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 m 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 m 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 m 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 m 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 mN %5$4$4:C:F,=Ym m m^ DMLX,= _t tkU=
T  UU=
r sU=
t +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! 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! 9! 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! 9!h  %$'-"($q9! 9! 9!t 6:$IE EuU=
@ $&+(-,1,0).+06:#'#'"&#(	( ( #($)$)+/27/4#()$ $, %)&*!$$*%+&*#'*/& & ',#'$)&*#'*/# # '+!$#'$)&*#'*/( ( '+!$$*%+#'$)&*#'*/
$ 
$ '+!$$*,-%+#'$)&*#'*/* *  #UM M^ y  )(, %)$(%)- -
 *.+/
$ 
$ %)%)& &# #( "#3 "#3 	  "#3 "#3 	 Yt tAU=
 U U U	    c                 F    |                                  | j        d         z
  S )Nr  )millisecondsrW  )r  s    r  noncezxt.nonce6  s!      ""T\2B%CCCr  c                     |                      |          }|                     |d          }|                     |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_time9  sB     ))&11 x22  |444r  c                 P   |                      |          |                     |          g}|\  }}|                     |dg           }|                     |dg           }|                     |dg           }|                     |d          }i }	t	          dt          |                    D ]}
||
         }|                     |d          }|                     |          }|                     ||i           }|                     |dg           }i }t	          dt          |                    D ]}||         }|                     |d          }|                     ||          }|||dd| 	                    |d          d| 
                    |d	          | 
                    |d
          ddd| 	                    |d          ddddddd
||<   |                     |d          }d}|dk    rd}nd}|                     ||||                     |d          dd|                     |                     |                     |d                              |                     |d          dk    |                     |d          dk    ||dddd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   supportChainschainNwithdrawFeeAmountdepositEnabledwithdrawEnabledminmaxwithdrawMinAmount)amountr   deposit)
infor-   networkr.   activefee	precisionr	  r   limitstypeFTcryptootherfullNamemaxPrecisiondepositStatus1withdrawStatus)r
  r-   coder.   r  r  r  r	  r   r  r  r  )"publicSpotGetWalletSupportCurrencypublicSpotGetCurrenciesr  index_byrangelensafe_stringsafe_currency_codenetwork_id_to_codesafe_number	safe_boolsafe_currency_structurer  parse_precision)r  r  promisesRawchainsResponsecurrenciesResponse
chainsDatacurrenciesResultcurrenciesDatachainsDataIndexedr  ientry
currencyIdr  networkEntryrawNetworksr  j
rawNetwork	networkIdnetworkCodetypeRawr  s                          r  fetch_currencieszxt.fetch_currenciesP  sC    >>vFFHdHdekHlHlm-8**h __^XrBB
??+=xLL)9<LL MM*jAAq#n--.. D	 D	A"1%E))%<<J**:66D??+<j"MML//,LLKH1c+..//  (^
 ,,ZAA	"55iFF&#* "++J8KLL!%#~~j:JKK $z;L M M $(#'# #
 $(#3#3J@S#T#T#'% %
 $(#'$ $ ) )%%2 &&uf55GD$77 ((
;;!..t/C/CDDTDTUZ\jDkDk/l/lmm++E?CCsJ ,,U4DEEL$  $# 
  $#! !
  $#    9 9  F4LL6 r  c                     | j         d         r|                                  |                     |          |                     |          g}|}|d         }|d         }|                     ||          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   )rW  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  s     <12 	(%%'''##F++..v66
 &qk'{  .BCCCr  c                     |                      |          }|                     |di           }|                     |dg           }|                     |          S )Nr  symbols)publicSpotGetSymbolr  parse_markets)r  r  r  r  rC  s        r  r:  zxt.fetch_spot_markets  sV    ++F33j x266//$	266!!'***r  c                    |                      |          |                     |          g}|                     |                     |d         dg           |                     |d         dg                     }|                     |          S )Nr   r  r   )-publicLinearGetFutureMarketV1PublicSymbolList.publicInverseGetFutureMarketV1PublicSymbolListr<  r  rE  )r  r  marketsr@  s       r  r;  z xt.fetch_swap_and_future_markets)  s    EEfMMt  PC  PC  DJ  PK  PK  L~  $00XWY1Z1Z\`\k\klstulv  yA  CE  ]F  ]F   G   G!!"6777r  c                     g }t          dt          |                    D ]0}|                    |                     ||                              1|S )Nr   )r  r  appendparse_market)r  rI  r  r-  s       r  rE  zxt.parse_marketsl  sR    q#g,,'' 	9 	9AMM$++GAJ778888r  marketc                 b	   |                      |d          }|                     |dd          }|                     |dd          }|                     |          }|                     |          }|                      |d          }|dz   |z   }|                     |dg           }	d }
d }d }d }d }d }d }t	          d	t          |	                    D ]}|	|         }|                      |d
          }|dk    rB|                     |d          }
|                     |d          }|                     |d          }|dk    r|                     |d          }|dk    r,|                     |d          }|                     |d          }|<|                     |                     |                      |d                              }|                      |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}|| 	                    |d          }|                      |d          }|dk    r |dz   | 
                    |          z   }d}d}nd}d}|                     |d          }
|                     |d           }|                     |d!          }|                     |d"          }|                     |d#          }d}d}d} |r|                     |d$d          } n4|d%k    r.|                     |d&          r|                     |d'          rd} |                     i d(|d|d)|d*|d+|d,|d-|d.|d/|d|d0d d|d|d1dd2| d3|d4|||                     |d5          |                     |d6          |                     |d7          ||                     |          d d |                     |                     |                      |d8                              ||                     |                     |                      |d9                              |                     |                     |                      |d:                              d;|                     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  rm  rn  r  r  )r]  r  ry  cost)r   r   r   ru  expiryexpiryDatetimestrike
optionTyper  r  r
  )r  safe_string_2r   r  r  r  r"  r  r%  r  yymmddsafe_market_structureiso8601)!r  rM  r-   rp  rq  rm  rn  rS  r   rU  	minAmount	maxAmountminCostmaxCostrg  rh  amountPrecisionr-  r.  rV  r\  r   r   rr  ro  r{  r=   r<   r   r:   r  ra  isActives!                                    r  rL  zxt.parse_marketr  s   j fh//##FNJGG$$V_kJJ&&v..''00  11e#//&)R88		q#g,,'' 	: 	:AAJE%%eX66F## ,,UE::	 ,,UE::	"&"2"25*"E"E$$**5%88  ++E599++E599""//0D0DTEUEUV\^qErEr0s0sttO))&2BCCY&&c\E)FHFFGG|++c\D(FHFFG%&&v~>>F**6=AAKk))#F(;(;;((::I&&v}==G&&v}==G''
;;H''
;;HHD 	 v{EBBHH!!@P(Q(Q!X\XgXghn  qA  YB  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9%%fj99 ,,V^DD"ll622**4+?+?@P@PQWYi@j@j+k+kll)))$*>*>t?O?OPVXk?l?l*m*mnn**4+?+?@P@PQWYm@n@n+o+opp	   ,,S11 
 %$ 
 $# 
 #"  $ e3+
 3+
 3+
 3 3 3	r  rI  Nr   	timeframesincer  c           	          |                                   d}|                     |ddd          \  }}|r|                     d|||||d          S |                     |          }|d         |                     | j        ||          d}|||d<   |||d	<   nd|d	<   |                     |d
          }	|                     |d
g          }|	|	|d<   d}
|d         r*|                     | 	                    ||                    }
n[|d         r*| 
                    | 	                    ||                    }
n)|                     | 	                    ||                    }
|                     |
dg           }|                     |||||          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
        Frp   paginater  r-   )r   intervalN	startTimer  untilendTimer   r   r  )load_marketshandle_option_and_params"fetch_paginated_call_deterministicrM  r  rH  r  omit)publicLinearGetFutureMarketV1PublicQKlineextend*publicInverseGetFutureMarketV1PublicQKlinepublicSpotGetKliner  parse_ohlcvs)r  r   r  r  r  r  r  rM  requestr  r  ohlcvss               r  fetch_ohlcvzxt.fetch_ohlcvg  s     	88z[`aa& 	x::<QVX]_hjprvwwwV$$Tl(()YOO
 
 #(GK $GG#GG!!&'226G9--!&GI( 	MEEdkkRY[aFbFbccHHI 	MFFt{{SZ\bGcGcddHH..t{{7F/K/KLLHT 8R88  E5IIIr  c           
         |d         rdnd}|                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d	|          gS )
Nr   vatohlcq)r  r"  safe_number_2)r  ohlcvrM  volumeIndexs       r  parse_ohlcvzxt.parse_ohlcv  s    8 %Y/9ccceS))UC((UC((UC((UC((uc;77
 	
r  c                 0   |                                   |                     |          }d|d         i}d}|d         r?|t          |d          |d<   |                     |                     ||                    }n~|t          |d          |d<   nd|d<   |d	         r*|                     |                     ||                    }n1|d
         r)|                     |                     ||                    }|                     |di           }|                     |dd          }|d         r2| 	                    |||          }	| 
                    |d          |	d<   |	S | 	                    |||dd          }
|                     |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  rM  r  publicSpotGetDepthr  )publicLinearGetFutureMarketV1PublicQDepth*publicInverseGetFutureMarketV1PublicQDepthr  safe_integer_2parse_order_bookr  )r  r   r  r  rM  r  r  	orderBookr  obswapObs              r  fetch_order_bookzxt.fetch_order_book  s    	V$$fTl
 &> 	i #&uc?? ..t{{7F/K/KLLHH #&ub>>  #% h iII$++V]_eJfJfgg	" iJJ4;;W^`fKgKghh^ OOHh;;	''	;DD	&> 	&&y&)DDB++I~FFBwKI&&y&)S#NN--inMMwr  c                 &   |                                   |                     |          }d|d         i}d}|d         r*|                     |                     ||                    }n[|d         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |d          }|d         r|                     |d         |          S |                     ||          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  rM  -publicLinearGetFutureMarketV1PublicQAggTickerr  .publicInverseGetFutureMarketV1PublicQAggTickerpublicSpotGetTicker24hr  parse_ticker)r  r   r  rM  r  r  r   s          r  fetch_tickerzxt.fetch_ticker;  s    	V$$fTl
 ( 	QII$++V]_eJfJfggHHI 	QJJ4;;W^`fKgKghhHH224;;w3O3OPPH^ 844&> 	8$$VAY777  000r  rC  c                 &   |                                   d}|0|                     |          }|                     |d                   }i }d}d}d}|                     d||          \  }}|                     d||          \  }}|dk    r*|                     |                     ||                    }ne|dk    s|dk    s|dk    r*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    |dg           }i }	t          dt          |                    D ]+}
|                     ||
         |          }|d	         }||	|<   ,|                     |	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_symbolsrM  handle_market_type_and_paramshandle_sub_type_and_params/publicInverseGetFutureMarketV1PublicQAggTickersr  .publicLinearGetFutureMarketV1PublicQAggTickersr  r  r  r  r  filter_by_array)r  rC  r  rM  r  r  r  r  tickersr  r-  r   r   s                r  fetch_tickerszxt.fetch_tickers  s    	))'22G[[,,F99.&RXYYf99.&RXYYiKKDKKX_agLhLhiiHH!!tv~~48;K;KJJ4;;W^`fKgKghhHH224;;w3O3OPPHb //(Hb99q#g,,'' 	$ 	$A&&wqz6::FH%F#F6NN##FHg>>>r  c                    |                                   |                     |          }i }d}||                     |d                   }d}|                     d||          \  }}|t	          | j        dz             |                     |                     ||                    }|                     |dg           }| 	                    ||          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   rN   z^ fetchBidsAsks() is not available for swap and future markets, only spot markets are supportedr  )
r  r  rM  r  r"   r-   publicSpotGetTickerBookr  r  parse_tickers)r  rC  r  r  rM  r  r  r  s           r  fetch_bids_askszxt.fetch_bids_asks  s     	%%g..[[,,F99/6SYZZtw  *J   J  K  K  K//GV0L0LMM$ //(Hb99!!'7333r  c                    |                      |d          }||d         nd }d|v pd|v }||rdnd}|                     ||d|          }|d         }|                     |d	          }|                     |d
d          }|t	          j        |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&|          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   rM  marketIdr  hasSpotKeysr   r  r   s	            r  r  zxt.parse_ticker  s   \ ##FC00(.(:VF^^
v~:46>#.>JJ!!(FCDD!%%fc22	''c::
! +J>>J !
f!
!
 Y//!
 D$$VS11	!

 4##FC00!
 4##FD11!
 ))&$77!
 4##FD11!
 ))&$77!
 D!
 D$$VS11!
 T%%fc22!
 D$$VS11!
 T!
 d&&vt44!
  $++J77!!
" t#!
$ **6377++FC88)!
 !
 !
* +  	r  c                    |                                   |                     |          }d|d         i}d}|d         r1|||d<   |                     |                     ||                    }nj|||d<   |d         r*|                     |                     ||                    }n1|d         r)|                     |                     ||                    }|                     |d	g           }|                     ||          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  rM  publicSpotGetTradeRecentr  (publicLinearGetFutureMarketV1PublicQDeal)publicInverseGetFutureMarketV1PublicQDealr  parse_trades)	r  r   r  r  r  rM  r  r  tradess	            r  fetch_tradeszxt.fetch_tradesR  s    	V$$fTl
 &> 
	h #( 44T[[&5Q5QRRHH !&h hHHU\^dIeIeff	" hII$++V]_eJfJfggJ 8R88  000r  c                    |                                   i }d}| |                     |          }|d         |d<   |||d<   d}d}d}	|                     d||          \  }}|                     d||          \  }}||dk    s|dk    ra|||d<   |d	k    r*|                     |                     ||                    }	n|                     |                     ||                    }	nVd}
|                     d|          \  }
}|
d
nd}||d<   |||d<   |                     |                     ||                    }	| 	                    |	di           }| 	                    |dg           }| 
                    ||||          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  ro   r<   r=   sizer   rY  rX  bizTyper  r  items)r  rM  r  r  ,privateInverseGetFutureTradeV1OrderTradeListr  +privateLinearGetFutureTradeV1OrderTradeListhandle_margin_mode_and_paramsprivateSpotGetTrader  r  )r  r   r  r  r  r  rM  r  r  r  r  marginOrSpotRequestr  r  s                 r  fetch_my_tradeszxt.fetch_my_trades  s    	[[((F &tGH#(GK 99/6SYZZf99/6SYZZTV^^9I9I "')##LLT[[Y`bhMiMijjKKDKKX_agLhLhiiJ!%!C!COU[!\!\J.8.D''6!4GI #( //GV0L0LMMHv x266w33  >>>r  c                    |                      |dd          }||d         nd }d|v pd|v pd|v }||rdnd}|                     ||d	|          }d }d }|                     |d          }|	|rd
nd}d}nv|                     |d          }	|	|	}n|                     |d          }
|
|
rdnd}|                     |d          }||}n"|                     |d          }|
|dk    rdnd
}|                     |g d          }|                      |dd          }d }|dk    r|}ns|Ct          j        |                     |d          |                     |d                             }n.t          j        ||                     |d                             }| 	                    || 
                    |g d          ||                     |          |d         |                      |dd          |                     |d          |||                      |dd          |d |                     |                      |dd                    |                     |d          d d!|          S )"Nr  r   r  r  r  oir:   r   r  sellbuyr   
takerMakerisMakerr   	orderSidemBID)r  r   r  r  quantityr  ru  )r-  tradeIdexecIdorderId	orderTypepry  feeCurrencyfeeCoinr  r  rz  )r
  r-   r  r  r   r   r  sidetakerOrMakerry  r  rz  r  )r  r  r#  safe_string_lowerr  safe_integer_nr(   r  number_to_string
safe_tradesafe_string_nr  r   )r  r   rM  r  r  r  r  r  isBuyerMakerr  r  r  bidOrAskr  r  r  s                   r  parse_tradezxt.parse_trade  s   X %%eS(;;(.(:VF^^
e|Oe);O#.>JJ!!(FCDD~~eS11#)466uD"LL//|DDJ%)..	::&.5#B777L..ukBBI$ ++E377'%-%6%655VD''/I/I/IJJ	%%eS*==FF +D,<,<UC,H,H$J_J_`fgu`vJwJwxx +Hd6K6KFSaLb6c6cdd$$U,F,F,FGG"Y//X&''y$??**5+>>(''sG<< 33D4F4Fum]f4g4ghh((66  
  
" #  	r  c                    |                                   d}d}d}|                     dd|          \  }}|                     dd|          \  }}|dk    p|dk    }|dk    r|                     |          }n3|dk    s|r|                     |          }n|                     |          }d}||r|                     |dg           }n.|                     |di           }|                     |dg           }|                     |          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>`
        NrM   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  s3    	99.$PVWWf99.$PVWW!V^B1AiDDVLLHH!!&6!CCFKKHH226::HZ $4x2>>HH??8Xr::DtXr::H!!(+++r  c                    d|i}t          dt          |                    D ]}||         }|                     |dd          }|                     |          }|                                 }|                     |dd          }|                     |d          }	|                     |dd	          }
|	ft          j        |                     |d
          |                     |d                    }t          j        |                     |d          |          }	||d<   |	|d<   |
|d<   |||<   |                     |          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  sc   6 (#q#h--(( 	# 	#AqkG++GZHHJ**:66DllnnG%%g/@BTUUD##G^<<D&&wOOE|+2+=d>N>NwXg>h>hjnjzjz  |C  EU  kV  kV  ,W  ,W()$*:*:7D[*\*\^vww"GFO"GFO$GG"F4LL  (((r  rz  c                     |                                   |                     |          }|d         st          | j        dz             |                     |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 onlyrM  r  r   )r  rM  r"   r-   create_order)r  r   rz  r  rM  s        r  !create_market_buy_order_with_costz$xt.create_market_buy_order_with_cost	  sh     	V$$f~ 	ftw)ddeee  5$6JJJr  r  r  r  ry  c                     |                                   |                     |          }|d         }|d         r|                     ||||||          S |                     ||||||          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  rM  create_spot_ordercreate_contract_order)r  r   r  r  r  ry  r  rM  s           r  r4  zxt.create_order+	  s{    0 	V$$!&> 	Y))&$feVTTT--fdD&%QWXXXr  c                 v   |                                   |                     |          }|d         |                                |                                d}d }	d }
|                     d|          \  }
}|
dnd}||d<   |dk    r|                     |dd	          }	|d
k    r|                     |d          }|                     |d          }|                     | j        dd          }|r{||t          | j
        dz             |                     |          }|                     |          }d }|t          j        ||          }n|}|                     ||          |d<   nP||n|}|                     ||          |d<   n0|                     |dd          }	|                     ||          |d<   |dk    s|dk    r|                     ||          |d<   |	|d<   |                     |                     ||                    }|                     |di           }|                     ||          S )Nr-   )r   r  r  rG   rY  rX  r  rM  r  r  r  rz  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GTCry  r   r  r  r  )r  rM  upperr  safe_string_upperr  r  r#  rW  r!   r-   r  r(   r  cost_to_precisionprice_to_precisionamount_to_precisionprivateSpotPostOrderr  r  parse_order)r  r   r  r  r  ry  r  rM  r  r  r  r  rz  r  amountStringpriceStringcostCalculated
amountCostr  r   s                       r  r7  zxt.create_spot_orderK	  su   V$$TlJJLLJJLL
 

 
!??vVV
F*4*@ggv0	800NNKu}}''77662248NN4<Qtvz4{4{14 U}$,*47  6P  ,P  Q  Q  Q'+'<'<V'D'D&*&;&;E&B&B.2 ,-4-?k-Z-ZNN-1N.2.D.DV^.\.\
++*.*:J*.*@*@*T*TGJ'00NNK#66vuEEGGFNN"&":":66"J"JGJ!,,,T[[&-I-IJJ (B77v...r  c                    |                                   |                     |          }|d         |                     ||          d}|                     |d          }	|	|	|d<   |                     |dd          }
|dk    r|
rdnd}||d	<   n|
rdnd}||d	<   d }|                     |d
d          }|                     |dd          }|                     |dd          }|d u}|d u}|d u}||s|s|                     ||          |d<   |r|                     |dd          |d<   |                     |dd          |d<   |                                |d<   |                     ||          |d<   |dk    rdnd}||d<   | 	                    |d
          }|d         r+| 
                    |                     ||                    }ny|d         r)|                     |                     ||                    }nF|s|r|r|                     ||          |d<   n|                     ||          |d<   | 	                    |ddg          }|d         r*|                     |                     ||                    }n|d         r)|                     |                     ||                    }n|                                |d<   |                                |d<   |d         r*|                     |                     ||                    }n1|d         r)|                     |                     ||                    }|                     ||          S )Nr-   )r   origQtyr  
reduceOnlyFr  SHORTLONGpositionSider  	stopPricestopLosstriggerStopPrice
takeProfittriggerProfitPricery  r;  r  LATEST_PRICEr  rM  STOP_MARKETSTOPentrustTyper   r   r  )r  rM  r@  r=  r  r  r?  r  r<  r  /privateLinearPostFutureTradeV1EntrustCreatePlanr  0privateInversePostFutureTradeV1EntrustCreatePlan1privateLinearPostFutureTradeV1EntrustCreateProfit2privateInversePostFutureTradeV1EntrustCreateProfit)privateLinearPostFutureTradeV1OrderCreate*privateInversePostFutureTradeV1OrderCreaterB  )r  r   r  r  r  ry  r  rM  r  r  rI  requestTyper  r  rN  rP  	isTrigger
isStopLossisTakeProfitrU  s                       r  r8  zxt.create_contract_order	  s   V$$Tl//??
 
 ,,V]CC"%0GM"__V\5AA
5==&0=''vK&1GN##%/=&&gK&1GN#))&.+NN%%fj:LMM''>RSS
!-	d*
"$. J J#'#:#:65#I#I  	i%)%;%;FMSX%Y%YGM"*.*:*:6CUWe*f*fG&'#'::<<GK #'#:#:6<#P#PGK ,0H,<,<--6K%0GM"YYv~66Fh oOOPTP[P[\cekPlPlmm	" oPPQUQ\Q\]dflQmQmnn 	i< 	i \.2.E.Efh.W.W*++040G0GPZ0[0[,-YYv
L'ABBFh qQQRVR]R]^egmRnRnoo	" qRRSWS^S^_fhnSoSopp#'::<<GK #'::<<GK h iII$++V]_eJfJfgg	" iJJ4;;W^`fKgKghh &111r  r-   c                    |                                   d}||                     |          }i }d}d}d}|                     d||          \  }}|                     d||          \  }}|                     |d          }	|                     |d          }
|	r||d<   n|
r||d<   n||d<   |	rr|                     |d          }|dk    r+|                     |                     ||                    }n2|                     |                     ||                    }n|
rp|                     |d          }|dk    r*| 	                    |                     ||                    }n| 
                    |                     ||                    }n|dk    r*|                     |                     ||                    }ne|d	k    s|d
k    s|dk    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |di           }|                     ||          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>`
        Nrv   stopstopLossTakeProfit	entrustIdprofitIdr
  r   r   r<   r=   r  )r  rM  r  r  r  r  /privateInverseGetFutureTradeV1EntrustPlanDetailr  .privateLinearGetFutureTradeV1EntrustPlanDetail1privateInverseGetFutureTradeV1EntrustProfitDetail0privateLinearGetFutureTradeV1EntrustProfitDetail)privateInverseGetFutureTradeV1OrderDetail(privateLinearGetFutureTradeV1OrderDetailprivateSpotGetOrderOrderIdrB  )r  r-   r   r  rM  r  r  r  r  r  rb  r   s               r  fetch_orderzxt.fetch_order	  s     	[[((F99,PVWWf99,PVWW//&&11!__V5IJJ 	$#%GK   	$"$GJ!#GI 	UYYvv..F)##OOPTP[P[\cekPlPlmmNNt{{[bdjOkOkll 	UYYv';<<F)##QQRVR]R]^egmRnRnooPPQUQ\Q\]dflQmQmnn	!!EEdkkRY[aFbFbccHH!!tv~~48;K;KDDT[[QXZ`EaEabbHH66t{{7F7S7STTHl (B77v...r  c                    |                                   i }d}| |                     |          }|d         |d<   |||d<   |||d<   d}d}d}	|                     d||          \  }}|                     d||          \  }}|                     |dd          }
|
rr|                     |ddg          }|d	k    r*|                     |                     ||                    }	n|                     |                     ||                    }	n|d	k    r*| 	                    |                     ||                    }	n|d
k    s|dk    s|dk    r*| 
                    |                     ||                    }	nOd}|                     d|          \  }}|dnd}||d<   |                     |                     ||                    }	|                     |	di           }|                     |dg           }|                     ||||          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  ry   r  ra  r   r   r<   r=   rY  rX  r  r  r  )r  rM  r  r  safe_value_2r  4privateInverseGetFutureTradeV1EntrustPlanListHistoryr  3privateLinearGetFutureTradeV1EntrustPlanListHistory.privateInverseGetFutureTradeV1OrderListHistory-privateLinearGetFutureTradeV1OrderListHistoryr  privateSpotGetHistoryOrderr  parse_orders)r  r   r  r  r  r  rM  r  r  r  r  r  r  r  orderss                  r  fetch_orderszxt.fetch_orderso
  sR    	[[((F &tGH#(GK $GG99-QWXXf99-QWXX##FIv>> 	UYYv	6':;;F)##TTUYU`U`ahjpUqUqrrSSTXT_T_`gioTpTpqq	!!JJ4;;W^`fKgKghhHH!!tv~~48;K;KII$++V]_eJfJfggHHJ!%!C!CMSY!Z!ZJ.8.D''6!4GI66t{{7F7S7STTH^ x266w33  >>>r  c                    |                                   i }d }| |                     |          }|d         |d<   |||d<   |||d<   d }d }	d }
|                     d||          \  }}|                     d||          \  }	}|                     |dd          }|                     |d          }|d	k    r|s|rd
|d<   n=|dk    rd|d<   n1|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<   |rt|                     |ddg          }|	dk    r+|                     |                     ||                    }
n| 	                    |                     ||                    }
n|rr|                     |d          }|	dk    r+| 
                    |                     ||                    }
n6|                     |                     ||                    }
n|	|dk    s|dk    rZ|	dk    r*|                     |                     ||                    }
n|                     |                     ||                    }
nd }|                     d|          \  }}|dnd}||d<   |d	k    rN|||d<   ||                     |d          }||d<   |                     |                     ||                    }
n)|                     |                     ||                    }
g }|                     |
d          }||                     |dg           }n|                     |
d          }|                     ||||          S )Nr-   r   r  r  rz   ra  r  rb  r  NOT_TRIGGEREDrS  r<   
UNFINISHEDclosed	TRIGGEREDFILLEDcanceledUSER_REVOCATIONCANCELEDr=   r   rY  rX  r  r  r  r  )r  rM  r  r  safe_bool_2r  r  -privateInverseGetFutureTradeV1EntrustPlanListr  ,privateLinearGetFutureTradeV1EntrustPlanList/privateInverseGetFutureTradeV1EntrustProfitList.privateLinearGetFutureTradeV1EntrustProfitList'privateInverseGetFutureTradeV1OrderList&privateLinearGetFutureTradeV1OrderListr  rs  privateSpotGetOpenOrder	safe_dict	safe_listrt  )r  statusr   r  r  r  r  rM  r  r  r  r  rb  r  r  ru  
resultDicts                    r  fetch_orders_by_statuszxt.fetch_orders_by_status  sK   [[((F &tGH#GFO#(GK 99:OQWY_``f99:OQWY_``""669==!__V5IJJV 0, 0#2  #/ x ,, ,#.  #+  z!! ., .#4  #-  %GG 	(( 	(W-@dfnnZ^bjZjZj ',$ "' 	VYYv	':;;F)##MMdkkZaciNjNjkkLLT[[Y`bhMiMijj 	VYYv';<<F)##OOPTP[P[\cekPlPlmmNNt{{[bdjOkOkll!tv~~48;K;K)##GGT[]cHdHdeeFFt{{SZ\bGcGcddJ!%!C!CDY[a!b!bJ.8.D''6!4GI$+0GK($"ii88G',GG$::4;;wPV;W;WXX77GV8T8TUUf ^^Hh77
!^^J<<FF^^Hh77F  >>>r  c                 4    |                      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PPr  c                 4    |                      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>`
        rz  r  r  s        r  fetch_closed_orderszxt.fetch_closed_orders$  s     " **8VUE6RRRr  c                 4    |                      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_orders7  s     " **:vueVTTTr  c                    |                                   d}||                     |          }i }d}d}d}|                     d||          \  }}|                     d||          \  }}|                     |dd          }	|                     |d          }
|	r||d<   n|
r||d<   n||d<   |	rt|                     |ddg          }|d	k    r+|                     |                     ||                    }n2| 	                    |                     ||                    }n|
rp|                     |d          }|d	k    r*| 
                    |                     ||                    }n|                     |                     ||                    }n|d	k    r*|                     |                     ||                    }ne|d
k    s|dk    s|dk    r*|                     |                     ||                    }n)|                     |                     ||                    }|dup|dk    p|dk    }|r|n|                     |di           }|                     ||          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  ra  rb  rc  rd  r
  r   r   r<   r=   r  )r  rM  r  r  rn  r  r  0privateInversePostFutureTradeV1EntrustCancelPlanr  /privateLinearPostFutureTradeV1EntrustCancelPlan6privateInversePostFutureTradeV1EntrustCancelProfitStop5privateLinearPostFutureTradeV1EntrustCancelProfitStop*privateInversePostFutureTradeV1OrderCancel)privateLinearPostFutureTradeV1OrderCancelprivateSpotDeleteOrderOrderIdrB  )r  r-   r   r  rM  r  r  r  r  r  rb  isContractResponser   s                r  cancel_orderzxt.cancel_orderJ  s     	[[((F99-QWXXf99-QWXX##FIv>>!__V5IJJ 	$#%GK   	$"$GJ!#GI 	XYYv	6':;;F)##PPQUQ\Q\]dflQmQmnnOOPTP[P[\cekPlPlmm 	XYYv';<<F)##VVW[WbWbcjlrWsWsttUUVZVaVabikqVrVrss	!!FFt{{SZ\bGcGcddHH!!tv~~48;K;KEEdkkRY[aFbFbccHH99$++gv:V:VWWH,  'd2]]DT\L\.[DOOHhXZ4[4[v...r  c                    |                                   i }d}| |                     |          }|d         |d<   d}d}d}|                     d||          \  }}|                     d||          \  }}|                     |dd          }|                     |d          }	|rt|                     |ddg          }|dk    r+|                     |                     ||                    }nX| 	                    |                     ||                    }n-|	rp|                     |d          }|dk    r*| 
                    |                     ||                    }n|                     |                     ||                    }n|dk    r*|                     |                     ||                    }n|d	k    s|d
k    s|dk    r*|                     |                     ||                    }nOd}
|                     d|          \  }
}|
dnd}||d<   |                     |                     ||                    }|                     |          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  ra  rb  r   r   r<   r=   rY  rX  r  )r  rM  r  r  rn  r  r  3privateInversePostFutureTradeV1EntrustCancelAllPlanr  2privateLinearPostFutureTradeV1EntrustCancelAllPlan9privateInversePostFutureTradeV1EntrustCancelAllProfitStop8privateLinearPostFutureTradeV1EntrustCancelAllProfitStop-privateInversePostFutureTradeV1OrderCancelAll,privateLinearPostFutureTradeV1OrderCancelAllr  privateSpotDeleteOpenOrder
safe_order)r  r   r  r  rM  r  r  r  r  rb  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J 	UYYv	6':;;F)##SSTXT_T_`gioTpTpqqRRSWS^S^_fhnSoSopp 	UYYv';<<F)##YYZ^ZeZefmouZvZvwwXXY]YdYdelntYuYuvv	!!II$++V]_eJfJfggHH!!tv~~48;K;KHHU\^dIeIeffHHJ!%!C!CDUW]!^!^J.8.D''6!4GI66t{{7F7S7STTH* OOH%%
 	
r  idsc                 L   |                                   d|i}d}||                     |          }d}|                     d||          \  }}|t          | j        dz             |                     |                     ||                    }|                     |          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  rM  r  r"   r-   privateSpotDeleteBatchOrderr  r  )r  r  r   r  r  rM  r  r  s           r  cancel_orderszxt.cancel_orders  s     	
 [[((F99.&RXYYtw  *B   B  C  C  C33DKK4P4PQQ OOH%%
 	
r  c                    |                      |d          }d|v rd|v pdnd}|                     ||d |          }|                     ||d |          }|                     |dd          }|                     |d          }|dk    r|n@t          j        |                     |          |                     |d	                             }|                     |d
          }	|dk    r|	n@t          j        |                     |	          |                     |d	                             }
|                     |d          }| 	                    i d|d| 
                    |g d          d|                     |dd          d|d|                     |          d|d|d|d|                     |dd          d|                      |d          dd d|                     |dd          d|                     |d          d|                     |d          d|                     |d          d |                     |d!          d"||
|                     |d#          d |                     |d$          |                     |                      |d%                    |                     |                      |d&                    |                     |d'          d(d d)|          S )*Nr   rL  r  r   r:   r   createdTimerH  ru  executedQtyupdatedTimer
  r-   )r
  r  cancelIdrc  rd  clientOrderIdclientModifyIdr  r  lastTradeTimestamplastUpdateTimestampr  r  r  postOnlyr  r  ry  r  rM  rN  rO  rP  rQ  r  
leavingQtyavgPricerS  r  r  r  )filled	remainingrz  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   rM  r  r  r   r  r  r  filledQuantityr  lastUpdatedTimestamps               r  rB  zxt.parse_order  s   ~ ##E844;IU;R;Rh%'6JY_
!!(FD*EE!!(FD*EE''v}EE	##E955(F229KDLaLabjLkLkmq  nC  nC  DJ  KY  DZ  n[  n[  :\  :\))%??$.&$8$8w?QRVRgRghvRwRwy}  zO  zO  PV  We  Pf  zg  zg  @h  @h#00FF  
E 
$$$U,f,f,fgg 
 T//HXYY 
 	 

 Y// 
 !"6 
 "#7 
 f 
 D,,UFKHH 
 4++E=AA 
  
 D,,UFKHH 
 T%%eW55 
 D,,UK@@ 
 ((0BCC 
  $**52FGG! 
" f# 
$ ))%>>''z::--d.>.>ug.N.NOO 33D4D4DUM4Z4Z[[((66  7 
  
  
8 9  	r  c                 P    dddddddddddddd}|                      |||          S )Nr  rz  r}  rejectedexpired)NEWPARTIALLY_FILLEDr|  r  REJECTEDEXPIREDry  rx  
TRIGGERINGr{  r~  PLATFORM_REVOCATIONHISTORYr  r  r  statusess      r  r  zxt.parse_order_status  sO     &""  # !)#- 
 
 &&999r  r  c                    |                                   i }d}||                     |          }|||d<   |||d<   d}d}d}	|                     dd|          \  }}|                     dd|          \  }}|dk    r*|                     |                     ||                    }	nS|dk    s|dk    s|dk    r*|                     |                     ||                    }	nt          | j        d	z             | 	                    |	d
i           }
| 	                    |
dg           }| 
                    ||||          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  rh   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  sy    	}}T**H#(GK $GG99-vVVf99-vVViEEdkkRY[aFbFbccHH!!tv~~48;K;KDDT[[QXZ`EaEabbHHtw  *U   U  V  V  V0 x266w33  5%@@@r  c                 ,   |                      |d          }|dk    rdnd}|                      |d          }|                     ||          }|                     |d          }|                     ||                      |d          |d d d |                     |                      |d                    |                     ||          |                     |d	          ||                     |          d |                     |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  s4    f--!U]]DD	%%dF33
%%j(;;%%dM::	%%""4.." $001A1A$1O1OPP//
HEE&&tX66"Y//%%dM::  '
 '
& '  	r  c           	      F    ddddddddd}|                      |||          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   s@    "% "'&	
 	

 
D$777r  c                    |                                   d}|                     |          \  }}|                     |          }|                     ||          }|                     d|d           |d         |d}|                     |                     ||                    }|                     |di           }|                     ||          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>`
        NrX   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  r5  r  r4  r  r  r  s	            r  fetch_deposit_addresszxt.fetch_deposit_address-  s     	"AA&IIV==&&++K>>	$$%:IyQQQ 
 
 44T[[&5Q5QRR 8R88))&(;;;r  c                     |                      |d          }|                     |           ||                     d |          d ||                      |d          dS )Naddressmemo)r
  r  r  r  tag)r  check_addressr   )r  depositAddressr  r  s       r  r  zxt.parse_deposit_addressQ  sk     "">9==7###"//h??##NF;;
 
 	
r  c                 r   |                                   i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	||||          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_depositsb  s     	}}T**H"*4.GJ#(GK $GG44T[[&5Q5QRR6 x266??4"55&&x5%PPPr  c                 r   |                                   i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	||||          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'66R6RSS6 x266oodGR88&&{HeUFSSSr  r  r  c                 H   |                      |           |                                  |                     |          }|                     ||          \  }}d}|                     |          \  }}|                     | j        di           }|                     ||||          }	|d         |	|                     ||          |d}
|||
d<   | 	                    | 
                    |
|                    }|                     |di           }|                     ||          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  rW  r  currency_to_precisionprivateSpotPostWithdrawr  parse_transaction)r  r  r  r  r  r  r  r5  networkIdsByCodesr4  r  r  r  s                r  r   zxt.withdraw  s-    	7###==&&99#vFFV"AA&IIV OODL*bII&&'8+tTRR	 00v>>	
 
 ?!GFO//GV0L0LMM 8R88%%fh777r  transactionr  c                    d|v rdnd}|                      |d          }|                     |d          }|                     |d          }|                     |                     |d          |          }|                     |d          }||n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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  rz  rate)commentr  internal)r  r  r   r"  r  r!  parse_transaction_status)r  r	  r  r  r  r  r  currencyCoder  r  r4  s              r  r  zxt.parse_transaction  s-   P (;66yyZ%%k=AA	"";	::V44..t/?/?Z/X/XZbcc{E22'*llT$$['::	
K
$"";55
 D$$[/BB
 	

 Y//
 t
 4++KDD
 
 w
 t
 T
 4
 D
 d&&{H==
 
  t..y,GG!
" d33D4D4D[RZ4[4[\\#
$ ' 
 1
 
 
 	
r  c                 D    dddddddd}|                      |||          S )Npendingr}  failedok)SUBMITREVIEWAUDITEDPENDINGCANCELFAILSUCCESSr  r  s      r  r  zxt.parse_transaction_statusB  s=       
 
 &&999r  r]  c                 t   |t          | j        dz             |                     |d          }|                     d|dddg           |dk     s|dk    rt	          | j        d	z             |                                  |                     |          }|d
         st          | j        dz             |d         ||d}d}|                     d||          \  }}d}|dk    r*| 	                    | 
                    ||                    }n)|                     | 
                    ||                    }|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 argumentrL  r   rK  rJ  r   }   z3 setLeverage() leverage should be between 1 and 125r   z- setLeverage() supports contract markets onlyr-   )r   rL  r]  r   )r   r-   r  r  r   r  rM  r   r  4privateInversePostFutureUserV1PositionAdjustLeverager  3privateLinearPostFutureUserV1PositionAdjustLeverage)	r  r]  r   r  rL  rM  r  r  r  s	            r  set_leveragezxt.set_leverageN  sd    >#DG.Y$YZZZ''??$$]L.SY[bRcdddqLLhnnTW'\\]]]V$$z" 	WDG&UUVVVTl( 
 

 99-QWXXiPPQUQ\Q\]dflQmQmnnHHOOPTP[P[\cekPlPlmmH r  c                 2    |                      ||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=margin-structure>`
        r  modify_margin_helperr  r   r  r  s       r  
add_marginzxt.add_marginz       ((GGGr  c                 2    |                      ||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=margin-structure>`
        SUBr)  r+  s       r  reduce_marginzxt.reduce_margin  r-  r  c                    |                      |d          }|                     d|dddg           |                                  |                     |          }|d         |||d}d }|                     d||          \  }}d }	|dk    r*|                     |                     ||                    }	n)|                     |                     ||                    }	|                     |	|          S )	NrL  r   rK  rJ  r-   )r   r;   r  rL  modifyMarginHelperr   )	r  r  r  rM  r  ,privateInversePostFutureUserV1PositionMarginr  +privateLinearPostFutureUserV1PositionMarginparse_margin_modification)
r  r   r  addOrReducer  rL  rM  r  r  r  s
             r  r*  zxt.modify_margin_helper  s   ''??$$]L.SY[bRcdddV$$Tl(	
 
 99:NPVX^__iHHU\^dIeIeffHHGGT[]cHdHdeeH --h???r  c                 D    |d d d |                      d |          d d d d d d
S )N)
r
  r  r  r  r   r  r  r.  r  r  )r  )r  r  rM  s      r  r5  zxt.parse_margin_modification  s?    &&tV44
 
 	
r  c                 N   |                                   d}|                     dd|          \  }}d}|dk    r|                     |          }n|                     |          }|                     |dg           }|                     |          }|                     ||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>`
        Nrk   r   r  r   )r  r  7publicInverseGetFutureMarketV1PublicLeverageBracketList6publicLinearGetFutureMarketV1PublicLeverageBracketListr  r  parse_leverage_tiers)r  rC  r  r  r  r  s         r  fetch_leverage_tierszxt.fetch_leverage_tiers  s     	99:NPTV\]]iSSTZ[[HHRRSYZZH2 x266%%g..((wAAAr  c                    i }t          dt          |                    D ]}||         }|                     |d          }|                     |d dd          }|                     ||          }	|0|                     |	|          r|                     ||          ||	<   |                     ||         |          ||	<   |S )Nr   r   r  r   )r  r  r  r  r  in_arrayparse_market_leverage_tiers)
r  r  rC  marketIdKeyr  r-  r.  r  rM  r   s
             r  r;  zxt.parse_leverage_tiers  s    $ q#h--(( 		W 		WAQKE''x88H%%hc:FFF%%h77F"==11 U%)%E%EeV%T%TF6N!%!A!A(1+v!V!Vvr  c                    |                                   |                     |          }d|d         i}d}|                     d||          \  }}d}|dk    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |di           }|                     ||          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-   Nrl   r   r  )r  rM  r  9publicInverseGetFutureMarketV1PublicLeverageBracketDetailr  8publicLinearGetFutureMarketV1PublicLeverageBracketDetailr  r?  )r  r   r  rM  r  r  r  r  s           r  fetch_market_leverage_tierszxt.fetch_market_leverage_tiers  s     	V$$fTl
 99:TV\^deeiUUVZVaVabikqVrVrssHHTTUYU`U`ahjpUqUqrrH. x266//f===r  c                 4   g }|                      |dg           }t          dt          |                    D ]}||         }|                     |d          }|                     ||dd          }|                    |                     |d          |                     ||dd          |d         |                     ||dz
           d	d          |                     |d	          |                     |d
          |                     |d          |d           |S )NleverageBracketsr   r   r  r   bracketro  r   maxNominalValuemaintMarginRatemaxLeverage)tierr   r  re  rf  maintenanceMarginRaterJ  r
  )	r  r  r  r  r  rK  r  r  r"  )r  r
  rM  r   bracketsr-  rK  r  s           r  r?  zxt.parse_market_leverage_tiers<  s0   $ ??4);R@@q#h--(( 	 	AA;D''h77H%%hZHHFLL))$	::**8VS*MM"8,#//QARTUVV#//6GHH)-)9)9$@Q)R)R#//mDD	 	 	 	 	 	 r  c                 v   |t          | j        dz             |                                  d}|                     |dd          \  }}|r|                     d||||dddd	  	        S |                     |          }|d	         st          | j        d
z             d|d         i}|||d<   nd|d<   d}|                     d||          \  }}d}	|dk    r*|                     | 	                    ||                    }	n)| 
                    | 	                    ||                    }	|                     |	di           }
|                     |
dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     ||          }|                     |d          }|                    |||                     |d          ||                     |          d           |                     |d          }|                     ||d         ||          S )a  
        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
        :param bool params['paginate']: True/false whether to use the pagination helper to aumatically paginate through the results
        :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 argumentFrc   r  r-   r      r<   z7 fetchFundingRateHistory() supports swap contracts onlyr   r  r   r  r  r   r  fundingRate)r
  r   rP  r  r  r  )r   r-   r  r  fetch_paginated_call_cursorrM  r   r  6publicInverseGetFutureMarketV1PublicQFundingRateRecordr  5publicLinearGetFutureMarketV1PublicQFundingRateRecordr  r  r  r  r  r  rK  r"  r  sort_byfilter_by_symbol_since_limit)r  r   r  r  r  r  rM  r  r  r  r  r  ratesr-  r.  r  symbolInnerr  sorteds                      r  fetch_funding_rate_historyzxt.fetch_funding_rate_history`  s    >#DG.e$efff88AZ\fgg& 	A334MvW\^cekmqswyz|  A  A  AV$$f~ 	aDG&__```fTl
 $GG"GG99:SU[]cddiRRSWS^S^_fhnSoSoppHHQQRVR]R]^egmRnRnooH* 8R8844q#e**%% 	 	A!HE''x88H**8V<<K))%??ILL%#//}EE& LL33      e[11009I5RWXXXr  c                 .    |                      ||          S )a_  
        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66r  c                    |                                   |                     |          }|d         st          | j        dz             d|d         i}d}|                     d||          \  }}d}|dk    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |di           }| 	                    ||          S )	aN  
        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-   Nrb   r   r  )
r  rM  r   r-   r  0publicInverseGetFutureMarketV1PublicQFundingRater  /publicLinearGetFutureMarketV1PublicQFundingRater  parse_funding_rate)r  r   r  rM  r  r  r  r  s           r  r[  zxt.fetch_funding_rate  s    	V$$f~ 	ZDG&XXYYYfTl
 99:LfV\]]iLLT[[Y`bhMiMijjHHKKDKKX_agLhLhiiH 8R88&&vv666r  c                    |                      |d          }|                     ||dd          }|                     |d          }|                      |d          }||dz   }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|iS )Nr   r  r<   nextCollectionTimecollectionInternalr  r
  	markPrice
indexPriceinterestRateestimatedSettlePricer  r  rP  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )r  r  r  r"  r  )r  r   rM  r  r   r  r  s          r  r`  zxt.parse_funding_rate  sl    ##Hh77!!(FC@@%%h0DEE	##H.BCC#~H
H
f
 
 $	

 D
 #D
 
 
 4++HmDD
 	
 t||I66
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
r  c                    |                                   |                     |          }|d         st          | j        dz             d|d         i}|||d<   |||d<   d}|                     d||          \  }}d}|d	k    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |d
i           }	|                     |	dg           }
g }t          dt          |
                    D ]3}|
|         }|                    |                     ||                     4|                     |d          }|                     |||          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  rM  r   r-   r  3privateInverseGetFutureUserV1BalanceFundingRateListr  2privateLinearGetFutureUserV1BalanceFundingRateListr  r  r  rK  parse_funding_historyrT  filter_by_since_limit)r  r   r  r  r  rM  r  r  r  r  r  r  r-  r.  rX  s                  r  fetch_funding_historyzxt.fetch_funding_history  s    	V$$f~ 	]DG&[[\\\fTl
 #(GK $GG99:OQWY_``iOOPTP[P[\cekPlPlmmHHNNt{{[bdjOkOkllH, x266gr22q#e**%% 	E 	EA!HEMM$44UFCCDDDDfk22))&%???r  c           
      j   |                      |d          }|                     ||dd          }|                      |d          }|                     |          }|                     |d          }|||||                     |          |                      |d          |                     |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   rM  r  r   r/  r  r  s           r  rs  zxt.parse_funding_history?  s     ##Hh77!!(FC@@%%h77
&&z22%%h>>	"Y//""8T22&&x88
 
 	
r  c                    |                                   |                     |          }d|d         i}d}|                     d||          \  }}d}|dk    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |dg           }t          dt          |                    D ]l}||         }	| 	                    |	d          }
| 
                    |
ddd          }| 	                    |	d	          }|d
k    r|                     |	|          c S mdS )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-   Nr|   r   r  r   r   positionSizer   )r  rM  r  )privateInverseGetFutureUserV1PositionListr  (privateLinearGetFutureUserV1PositionListr  r  r  r  r  parse_position)r  r   r  rM  r  r  r  	positionsr-  r.  r  marketInnerry  s                r  fetch_positionzxt.fetch_positionY  se    	V$$fTl
 99/6SYZZiEEdkkRY[aFbFbccHHDDT[[QXZ`EaEabbH4 OOHh;;	q#i..)) 	? 	?AaLE''x88H**8T4LLK++E>BBLs""**5+>>>>> #tr  c                 (   |                                   d}|                     dd|          \  }}d}|dk    r|                     |          }n|                     |          }|                     |dg           }g }t          dt          |                    D ]a}||         }|                     |d          }	|                     |	ddd          }
|	                    | 
                    ||
                     b|                     |d|d          S )	ah  
        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>`
        Nr}   r   r  r   r   r   F)r  r  rz  r{  r  r  r  r  r  rK  r|  filter_by_array_positions)r  rC  r  r  r  r}  r  r-  r.  r  r~  s              r  fetch_positionszxt.fetch_positions  s#    	99:JDRXYYiEEfMMHHDDVLLH4 OOHh;;	q#i..)) 	C 	CAaLE''x88H**8T4LLKMM$--e[AABBBB--fhOOOr  c           
      H   |                      |d          }|                     ||d d          }|                     ||d d          }|                      |d          }|dk    rdnd}|                     |d          }|                     i d|d	d d|d
d dd dd d|                     |d          d|                     |d          d|d         d|                     |d          dd dd d|                     |d          d|d|dd dd d d d |d d d          S )Nr   r   positionTypeCROSSEDcrossisolatedr*  r
  r-   r  r  r  r  rL  	contractsry  ru  
entryPricerd  notionalr]  
collateralinitialMarginmaintenanceMargininitialMarginPercentage)maintenanceMarginPercentageunrealizedPnlliquidationPricer  r   marginRatio)r  r  r  r"  safe_positionr  r  )r  positionrM  r  r   r  r  r  s           r  r|  zxt.parse_position  s   & ##Hh77!!(FD*EE!!(FD*EE''.AA!-!:!:WW
%%h0@AA
!! #
H#
$#
 f#
 	#

 #
 d#
 D**8^DD#
 ))(NCC#
 F>2#
 $**8\BB#
 #
 #
 ))(J??#
 *#
 Z#
   !#
" &t##
$ ,0! $$/#
 #
 #
   	r  fromAccount	toAccountc                    |                                   |                     |          }|                     | j        d          }|                     |||          }|                     |||          }	|                     ||          }
|                                 |d         |
||	d}|                     |                     ||                    }| 	                    ||          S )aF  
        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  rW  r  r  uuidprivateSpotPostBalanceTransferr  parse_transfer)r  r  r  r  r  r  r  accountsByTypefromAccountIdtoAccountIdrC  r  r  s                r  r   zxt.transfer  s     	==&&~FF((kRR&&~y)LL11$??YY[[ "!
 
 66t{{7F7S7STT ""8X666r  c           
      B    ||                      |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#  s<    ""8X66

 

 
	
r  r  c                    |t          | j        dz             |                                  |                     |          }|d         rt	          | j        dz             |                                }|dk    r|dk    rt          | j        dz             |dk    rd}nd	}|                     |d
          }|t          | j        dz             |||d         d}|                     | 	                    ||                    }|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
        Nz+ setMarginMode() requires a symbol argumentr:   z/ setMarginMode() supports contract markets onlyr  r  z@ setMarginMode() marginMode argument should be isolated or crossr  ISOLATEDrL  zL setMarginMode() requires a positionSide parameter, either "LONG" or "SHORT"r-   )r  rL  r   )
r   r-   r  rM  r   lowerr   r=  /privateLinearPostFutureUserV1PositionChangeTyper  )r  r  r   r  rM  posSider  r  s           r  set_margin_modezxt.set_margin_mode0  s-    >#DG.[$[\\\V$$&> 	YDG&WWXXX%%''
##
g(=(=TW'iijjj  "JJ#J((@@?#DG.|$|}}}&#Tl
 

 GGT[]cHdHdee r  c                    |t          | j        dz             |                                  |                     |          }i }	|                     |dd          }
|                     |dd          }|                     |ddg          }|
du}|du}|s|r||	d<   n||	d<   |                     ||          |	d	<   d}|d
         r#|r|                     ||
          |	d<   n5||                     ||          |	d<   n|                     ||          |	d<   d}|                     d||          \  }}|dk    rX|s|r*| 	                    | 
                    |	|                    }n|                     | 
                    |	|                    }n|s|r*|                     | 
                    |	|                    }nl|                     | 
                    |	|                    }nB|                     ||          |	d<   |                     | 
                    |	|                    }|d
         r|n|                     |di           }|                     ||          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 argumentrN  rO  rP  rQ  rd  r
  ry  r<   rH  rJ   r   r  r  )r   r-   r  rM  r  r  r?  r@  r  6privateInversePostFutureTradeV1EntrustUpdateProfitStopr  *privateInversePostFutureTradeV1OrderUpdate5privateLinearPostFutureTradeV1EntrustUpdateProfitStop)privateLinearPostFutureTradeV1OrderUpdateprivateSpotPutOrderOrderIdr  rB  )r  r-   r   r  r  r  ry  r  rM  r  rN  rP  r^  r_  r  r  r  s                    r  
edit_orderzxt.edit_order_  s   & >#DG.X$XYYYV$$%%fj:LMM''>RSS
6J#=>>d*
"$. 	F 	F"$GJ!#GI#66vuEEGG&> %	U N.2.E.Efh.W.W*++'040G0GPZ0[0[,--%)%=%=ff%M%M	"G"==k6SYZZOGV)## m m#ZZ[_[f[fgnpv[w[wxxHH#NNt{{[bdjOkOkllHH  l l#YYZ^ZeZefmouZvZvwwHH#MMdkkZaciNjNjkkHH #'":":66"J"JGJ66t{{7F7S7STTH %VnY4>>(HVX3Y3Y///r  c
                    |                      |dd          }
|
|
dk    r| j        dz   |z   }|                     |di           }|                     |d          }|                     |d|          }|                     |d          }|                     |d|          }|                     | j        d         ||           |                     | j        d	         ||           t          |          d S )
NmsgInfomcr"   errorr  msgrF  rG  )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D&I"5"5w}t+HOOHgr::E ,,Xt<<M((FFI**8Y??K&&ue[AAG001I9V^___001I7T\]]])))tr  GETc                     |d         dk    }|d         }d|                      ||          z   }	d }
|dk    s|dk    r!|rd| j        z   |	z   }
nd| j        z   dz   |	z   }
n|	}
| j        d         |         |
z   }|                     ||                     |                    }|                     |                     |                    }d	d
i}|r2|                                  |                     | j	        d          }|                     |d|          }| 
                    |                                           }|}|
dk    s|
dk    s|
dk    s|
dk    s|
dk    r&d}|
                    d          dk    r||d<   n||d<   |dk    p|dk    p|dk    }|dk    r|dk    rd}|rd n|                     |          }d }|dk    s|dk    rd| j        z   dz   |z   dz   dz   |z   }|rT|rC|d|z   z  }|d |z   d z   |
z   d z   |                     |                     |                    z   z  }n#|d |z   d z   |
z   z  }n|d |z   d z   |
z   d z   |z   z  }d!|d"<   ||d#<   nId$| 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                  t&          j                  }| j        |d%<   ||d&<   ||d'<   n
|r|d|z   z  }||||d(S ))Nr   r   r   rT  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  rW  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9H$6$6 C,w6,y87BGix(72		&$"5"5d";";<<^^DLL$7$788
.
  -	(++--- $ 0 0| L L))%?PQQJ--djjll;;ID;&&G7V,V,V\c  hN  ]N  ]N  T[  _G  TG  TG  MT  X}  M}  M}<<))B..*,D''$&DM &%gT=N5NgTX\fTfO%h&&8&8"'*?44		$D MF""F(:(: WZ^Ze e  iC  !C  FP  !P  Sc  !c  fq  !q  t}  !}" O! FsZ//%v);g)E)Kdnn]a]i]ijo]p]pNqNq)qq%v);g)EE!S6\C%7'%AC%G$%NNM4@014>011 5 CFV VYd dgp pU??! 7sZ//%w)<z)II%w6!S7]S%84%??M		$++m"<"<dkk$+>V>VX_XfggI,0KG()/8G+,/8G+,, (sZ''fdwOOOr  )N)NN)d__name__
__module____qualname__r   r  r  r	   r  r   r7  r   r   rA  r:  r;  rE  dictrL  strr  listr  r  r  r   r  r  r  r  r  r  r!  r  floatr5  r   r   r   r4  r7  r8  rl  rv  r  r  r  r  r  r  r   r  rB  r  r   r
   r  r  r  r   r  r  r  r  r   r   r   r  r  intr'  r,  r0  r   r*  r5  r   r<  r;  r   rD  r?  rY  r   r\  r[  r`  ru  rs  r  r   r  r|  r   r   r  r  r  r  r  __classcell__)r  s   @r  r*   r*      s       V# V V V V V VpD D D !# 5 5s 5 5 5 5. ') H HZ H H H HT $& D D$v, D D D D* )+ 8+ 8+ 8+ 8+t 46 A8 A8 A8 A8F  s4 sF s s s sj 9=4^bkm UJ UJ# UJ# UJS UJX[ UJ UJ UJ UJn$
 $
 $
4 $
 $
 $
 $
L :>b U Us U3 U U U Un 02 H1 H13 H1 H1 H1 H1T 26b R? R?T#Y R?W R? R? R? R?h 48 '4 '4tCy '4 '4 '4 '4RN N N N` 6:UW C1 C13 C1s C1# C1 C1 C1 C1J -1tRV_a e? e?c e? e?C e? e? e? e?Nb b b bH $& I, I, I, I,V+) +) +)Z RT K K K5 K K K K" gksu Y Y3 Yi Yy YRW Y`c Y Y Y Y@ HLTV 4/ 4/ 4/ 4/ 4/ 4/l LPXZ @2 @2C @2 @2 @2 @2D 26b j/ j/c j/3 j/ j/ j/ j/X *.Dt\^ _? _?3 _?c _? _? _? _? _?B <@daenp ? ?S ? ?[^ ? ? ? ?B /3TXac Q Q Q3 Qc Q Q Q Q& 154VZce S S# SS SPS S S S S& 37TX\eg U UC Us URU U U U U& 37r K/ K/s K/C K/ K/ K/ K/Z /32 G
 G
 G
 G
 G
 G
R ;?r #
 #
c #
C #
dSXk #
 #
 #
 #
Je e e eN: : :$ (,$TZ\ 9A 9A 9AC 9As 9Aaefqar 9A 9A 9A 9Av% % % % % %N8 8 8 79 "< "<# "<^ "< "< "< "<H
 
n 
 
 
 
" *.Dt\^ 3Q 3Q3 3Qc 3Q 3Q 3Q 3Q 3Qj -1tRV_a 3T 3Tc 3T 3TC 3T 3T 3T 3Tj KOWY )8 )8S )8% )8# )8C )8^i )8 )8 )8 )8VI
 I
T I
X I
Q\ I
 I
 I
 I
V
: 
: 
: 9=R * *S *# * * * *X =? H H He H H H H @B H HC H H H H H MO @ @3 @Se @ @ @ @8
 
>P 
 
 
 
 9=R ,B ,BDI ,BM ,B ,B ,B ,B\ P]    > ?A -> -># ->T,EW -> -> -> ->^" "\@R " " " "H 8<$]ajl IY IY IYC IYWZ IY IY IY IYV :< 
7 
7S 
7 
7 
7 
7 
7 68 &7 &7 &7K &7 &7 &7 &7P"
 "
; "
 "
 "
 "
H 37TX\eg :@ :@C :@s :@RU :@ :@ :@ :@x
 
 
 
4 24 7 7S 7 7 7 7r 48 2P 2PtCy 2PtH~ 2P 2P 2P 2Ph1 1 1 1f [] (7 (7S (7% (7c (7c (7an (7 (7 (7 (7T
 
 
 
 >B" - -# -s - - - -^ `drv  @B V0 V0S V0# V0Y V0i V0Y\ V0lo V0  GL V0 V0 V0 V0p@ @ @D  b$T @P @P @P @P @P @P @P @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     s   ( ' ' ' ' ' ( ( ( ( ( (  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) . . . . . . * * * * * * + + + + + + 4 4 4 4 4 4 % % % % % %]LP ]LP ]LP ]LP ]LP; ]LP ]LP ]LP ]LP ]LPr  