
    eiT                    d   d dl mZ d dlmZ d dl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    S/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/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.nonce7  s!      ""T\2B%CCCr  c                    K   |                      |           d{V }|                     |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
        Nresult
serverTime)publicSpotGetTime
safe_valuesafe_integer)r  paramsresponsedatas       r  
fetch_timezxt.fetch_time:  sX       //77777777 x22  |444r  c                 x  K   |                      |          |                     |          g}t          j        |  d{V \  }}|                     |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
        Nr  r   currencyr   supportChainschain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publicSpotGetCurrenciesasynciogatherr  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_currenciesQ  s`      >>vFFHdHdekHlHlm3:>;3O-O-O-O-O-O-O**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                   K   | j         d         r|                                  d{V  |                     |          |                     |          g}t	          j        |  d{V }|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  Nr   r   )rW  load_time_differencefetch_spot_marketsfetch_swap_and_future_marketsr  r  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                    K   |                      |           d {V }|                     |di           }|                     |dg           }|                     |          S )Nr  symbols)publicSpotGetSymbolr  parse_markets)r  r  r  r  rE  s        r  r<  zxt.fetch_spot_markets  sl      11&99999999j x266//$	266!!'***r  c                 @  K   t          j        |                     |          |                     |          g  d {V }|                     |                     |d         dg           |                     |d         dg                     }|                     |          S )Nr   r  r   )r  r  -publicLinearGetFutureMarketV1PublicSymbolList.publicInverseGetFutureMarketV1PublicSymbolListr>  r  rG  )r  r  marketsrB  s       r  r=  z xt.fetch_swap_and_future_markets*  s      )[)[\b)c)cei  fY  fY  Z`  fa  fa  )b  c  c  c  c  c  c  c~  $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  rK  r  r/  s       r  rG  zxt.parse_marketsm  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  ro  rp  r  r  )r]  r  r{  cost)r   r   r   rw  expiryexpiryDatetimestrike
optionTyper  r  r
  )r!  safe_string_2r"  r  r  r   r$  r  r'  r  yymmddsafe_market_structureiso8601)!r  rO  r-   rr  rs  ro  rp  rU  r   rW  	minAmount	maxAmountminCostmaxCostri  rj  amountPrecisionr/  r0  rX  r^  r   r   rt  rq  r}  r=   r<   r   r:   r  rc  isActives!                                    r  rN  zxt.parse_markets  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           	      `  K   |                                   d{V  d}|                     |ddd          \  }}|r!|                     d|||||d           d{V S |                     |          }|d         |                     | j        ||          d}|||d<   |||d	<   nd|d	<   |                     |d
          }	|                     |d
g          }|	|	|d<   d}
|d         r0|                     | 	                    ||                     d{V }
ng|d         r0| 
                    | 	                    ||                     d{V }
n/|                     | 	                    ||                     d{V }
|                     |
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
        NFrp   paginater  r-   )r   interval	startTimer  untilendTimer   r   r  )load_marketshandle_option_and_params"fetch_paginated_call_deterministicrO  r!  rH  r  omit)publicLinearGetFutureMarketV1PublicQKlineextend*publicInverseGetFutureMarketV1PublicQKlinepublicSpotGetKliner  parse_ohlcvs)r  r   r  r  r  r  r  rO  requestr  r  ohlcvss               r  fetch_ohlcvzxt.fetch_ohlcvh  s*       !!!!!!!!!88z[`aa& 	~@@vW\^cenpvx|}}}}}}}}}V$$Tl(()YOO
 
 #(GK $GG#GG!!&'226G9--!&GI( 	S!KKDKKX_agLhLhiiiiiiiiHHI 	S!LLT[[Y`bhMiMijjjjjjjjHH!44T[[&5Q5QRRRRRRRRHT 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  ohlcvrO  volumeIndexs       r  parse_ohlcvzxt.parse_ohlcv  s    8 %Y/9ccceS))UC((UC((UC((UC((uc;77
 	
r  c                 d  K   |                                   d{V  |                     |          }d|d         i}d}|d         rE|t          |d          |d<   |                     |                     ||                     d{V }n|t          |d          |d<   nd|d<   |d	         r0|                     |                     ||                     d{V }n7|d
         r/|                     |                     ||                     d{V }|                     |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
        Nr   r-   r:   i  r  2   levelr   r   r  	timestampr  lastUpdateIdr  br  u)r  rO  r  publicSpotGetDepthr  )publicLinearGetFutureMarketV1PublicQDepth*publicInverseGetFutureMarketV1PublicQDepthr  safe_integer_2parse_order_bookr  )r  r   r  r  rO  r  r  	orderBookr  obswapObs              r  fetch_order_bookzxt.fetch_order_book  s      !!!!!!!!!V$$fTl
 &> 	o #&uc?? !44T[[&5Q5QRRRRRRRRHH #&ub>>  #% h o!%!O!OPTP[P[\cekPlPl!m!mmmmmmm	" o!%!P!PQUQ\Q\]dflQmQm!n!nnnnnnn^ OOHh;;	''	;DD	&> 	&&y&)DDB++I~FFBwKI&&y&)S#NN--inMMwr  c                 Z  K   |                                   d{V  |                     |          }d|d         i}d}|d         r0|                     |                     ||                     d{V }ng|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |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>`
        Nr   r-   r   r   r  r:   r   )r  rO  -publicLinearGetFutureMarketV1PublicQAggTickerr  .publicInverseGetFutureMarketV1PublicQAggTickerpublicSpotGetTicker24hr  parse_ticker)r  r   r  rO  r  r  r   s          r  fetch_tickerzxt.fetch_ticker<  si      !!!!!!!!!V$$fTl
 ( 	W!OOPTP[P[\cekPlPlmmmmmmmmHHI 	W!PPQUQ\Q\]dflQmQmnnnnnnnnHH!88Wf9U9UVVVVVVVVH^ 844&> 	8$$VAY777  000r  rE  c                 Z  K   |                                   d{V  d}|0|                     |          }|                     |d                   }i }d}d}d}|                     d||          \  }}|                     d||          \  }}|dk    r0|                     |                     ||                     d{V }nq|dk    s|dk    s|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }| 	                    |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_symbolsrO  handle_market_type_and_paramshandle_sub_type_and_params/publicInverseGetFutureMarketV1PublicQAggTickersr  .publicLinearGetFutureMarketV1PublicQAggTickersr  r  r  r   r  filter_by_array)r  rE  r  rO  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!QQRVR]R]^egmRnRnooooooooHH!!tv~~48;K;K!PPQUQ\Q\]dflQmQmnnnnnnnnHH!88Wf9U9UVVVVVVVVHb //(Hb99q#g,,'' 	$ 	$A&&wqz6::FH%F#F6NN##FHg>>>r  c                   K   |                                   d{V  |                     |          }i }d}||                     |d                   }d}|                     d||          \  }}|t	          | j        dz             |                     |                     ||                     d{V }|                     |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  rO  r  r"   r-   publicSpotGetTickerBookr  r  parse_tickers)r  rE  r  r  rO  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55dkk'66R6RSSSSSSSS$ //(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   rO  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                 @  K   |                                   d{V  |                     |          }d|d         i}d}|d         r7|||d<   |                     |                     ||                     d{V }nv|||d<   |d         r0|                     |                     ||                     d{V }n7|d         r/|                     |                     ||                     d{V }|                     |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>`
        Nr   r-   r:   r  numr   r   r  )r  rO  publicSpotGetTradeRecentr  (publicLinearGetFutureMarketV1PublicQDeal)publicInverseGetFutureMarketV1PublicQDealr  parse_trades)	r  r   r  r  r  rO  r  r  tradess	            r  fetch_tradeszxt.fetch_tradesS  so      !!!!!!!!!V$$fTl
 &> 
	n #( !::4;;wPV;W;WXXXXXXXXHH !&h n!%!N!Nt{{[bdjOkOk!l!lllllll	" n!%!O!OPTP[P[\cekPlPl!m!mmmmmmmJ 8R88  000r  c                 B  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   d}d}d}	|                     d||          \  }}|                     d||          \  }}||dk    s|dk    rm|||d<   |d	k    r0|                     |                     ||                     d{V }	n|                     |                     ||                     d{V }	n\d}
|                     d|          \  }
}|
d
nd}||d<   |||d<   |                     |                     ||                     d{V }	| 	                    |	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  rO  r  r  ,privateInverseGetFutureTradeV1OrderTradeListr  +privateLinearGetFutureTradeV1OrderTradeListhandle_margin_mode_and_paramsprivateSpotGetTrader  r  )r  r   r  r  r  r  rO  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 "')##!%!R!RSWS^S^_fhnSoSo!p!ppppppp!%!Q!QRVR]R]^egmRnRn!o!oooooooJ!%!C!COU[!\!\J.8.D''6!4GI #( !55dkk'66R6RSSSSSSSSHv 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  rw  )r/  tradeIdexecIdorderId	orderTypepr{  feeCurrencyfeeCoinr  r  r|  )r
  r-   r  r  r   r   r  sidetakerOrMakerr{  r  r|  r  )r  r  r%  safe_string_lowerr!  safe_integer_nr(   r  number_to_string
safe_tradesafe_string_nr  r"  )r  r   rO  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                 J  K   |                                   d{V  d}d}d}|                     dd|          \  }}|                     dd|          \  }}|dk    p|dk    }|dk    r|                     |           d{V }n?|dk    s|r|                     |           d{V }n|                     |           d{V }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  s      !!!!!!!!!99.$PVWWf99.$PVWW!V^B1Ai!JJ6RRRRRRRRHH!!&6!!II&QQQQQQQQHH!88@@@@@@@@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   r1  r  r1  r.  r/  r0  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  r|  c                    K   |                                   d{V  |                     |          }|d         st          | j        dz             |                     |dd|d|           d{V 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>`
        Nr:   z9 createMarketBuyOrderWithCost() supports spot orders onlyrO  r  r   )r  rO  r"   r-   create_order)r  r   r|  r  rO  s        r  !create_market_buy_order_with_costz$xt.create_market_buy_order_with_cost	  s       !!!!!!!!!V$$f~ 	ftw)ddeee&&vxaPPPPPPPPPr  r  r  r  r{  c                   K   |                                   d{V  |                     |          }|d         }|d         r |                     ||||||           d{V S |                     ||||||           d{V 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>`
        Nr   r:   )r  rO  create_spot_ordercreate_contract_order)r  r   r  r  r  r{  r  rO  s           r  r6  zxt.create_order,	  s      0 !!!!!!!!!V$$!&> 	_//dFESYZZZZZZZZZ33FD$PUW]^^^^^^^^^r  c                   K   |                                   d {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 {V }|                     |di           }|                     ||          S )Nr-   )r   r  r  rG   rY  rX  r  rO  r  r  r  r|  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GTCr{  r  r  r	  r  )r  rO  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  r{  r  rO  r  r  r  r  r|  r  amountStringpriceStringcostCalculated
amountCostr  r   s                       r  r9  zxt.create_spot_orderL	  s     !!!!!!!!!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!,224;;w3O3OPPPPPPPP (B77v...r  c                 
  K   |                                   d {V  |                     |          }|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         r1| 
                    |                     ||                     d {V }n|d         r/|                     |                     ||                     d {V }n^|s|r|r|                     ||          |d<   n|                     ||          |d<   | 	                    |ddg          }|d         r0|                     |                     ||                     d {V }n|d         r/|                     |                     ||                     d {V }n|                                |d<   |                                |d<   |d         r0|                     |                     ||                     d {V }n7|d         r/|                     |                     ||                     d {V }|                     ||          S )Nr-   )r   origQtyr  
reduceOnlyFr  SHORTLONGpositionSider  	stopPricestopLosstriggerStopPrice
takeProfittriggerProfitPricer{  r=  r  LATEST_PRICEr  rO  STOP_MARKETSTOPentrustTyper   r   r  )r  rO  rB  r?  r  r  rA  r!  r>  r  /privateLinearPostFutureTradeV1EntrustCreatePlanr  0privateInversePostFutureTradeV1EntrustCreatePlan1privateLinearPostFutureTradeV1EntrustCreateProfit2privateInversePostFutureTradeV1EntrustCreateProfit)privateLinearPostFutureTradeV1OrderCreate*privateInversePostFutureTradeV1OrderCreaterD  )r  r   r  r  r  r{  r  rO  r  r  rK  requestTyper  r  rP  rR  	isTrigger
isStopLossisTakeProfitrW  s                       r  r:  zxt.create_contract_order	  si     !!!!!!!!!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  	o%)%;%;FMSX%Y%YGM"*.*:*:6CUWe*f*fG&'#'::<<GK #'#:#:6<#P#PGK ,0H,<,<--6K%0GM"YYv~66Fh u!%!U!UVZVaVabikqVrVr!s!sssssss	" u!%!V!VW[WbWbcjlrWsWs!t!ttttttt 	o< 	o \.2.E.Efh.W.W*++040G0GPZ0[0[,-YYv
L'ABBFh w!%!W!WX\XcXcdkmsXtXt!u!uuuuuuu	" w!%!X!XY]YdYdelntYuYu!v!vvvvvvv#'::<<GK #'::<<GK h o!%!O!OPTP[P[\cekPlPl!m!mmmmmmm	" o!%!P!PQUQ\Q\]dflQmQm!n!nnnnnnn &111r  r-   c                 
  K   |                                   d{V  d}||                     |          }i }d}d}d}|                     d||          \  }}|                     d||          \  }}|                     |d          }	|                     |d          }
|	r||d<   n|
r||d<   n||d<   |	r~|                     |d          }|dk    r1|                     |                     ||                     d{V }nV|                     |                     ||                     d{V }n%|
r||                     |d          }|dk    r0| 	                    |                     ||                     d{V }n| 
                    |                     ||                     d{V }n|dk    r0|                     |                     ||                     d{V }nq|d	k    s|d
k    s|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |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  rO  r  r  r  r  /privateInverseGetFutureTradeV1EntrustPlanDetailr  .privateLinearGetFutureTradeV1EntrustPlanDetail1privateInverseGetFutureTradeV1EntrustProfitDetail0privateLinearGetFutureTradeV1EntrustProfitDetail)privateInverseGetFutureTradeV1OrderDetail(privateLinearGetFutureTradeV1OrderDetailprivateSpotGetOrderOrderIdrD  )r  r-   r   r  rO  r  r  r  r  r  rd  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 	[YYvv..F)##!%!U!UVZVaVabikqVrVr!s!sssssss!%!T!TUYU`U`ahjpUqUq!r!rrrrrrr 	[YYv';<<F)##!%!W!WX\XcXcdkmsXtXt!u!uuuuuuu!%!V!VW[WbWbcjlrWsWs!t!ttttttt	!!!KKDKKX_agLhLhiiiiiiiiHH!!tv~~48;K;K!JJ4;;W^`fKgKghhhhhhhhHH!<<T[[RX=Y=YZZZZZZZZHl (B77v...r  c                 j  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   d}d}d}	|                     d||          \  }}|                     d||          \  }}|                     |dd          }
|
r~|                     |ddg          }|d	k    r0|                     |                     ||                     d{V }	n|                     |                     ||                     d{V }	n|d	k    r0| 	                    |                     ||                     d{V }	n|d
k    s|dk    s|dk    r0| 
                    |                     ||                     d{V }	nUd}|                     d|          \  }}|dnd}||d<   |                     |                     ||                     d{V }	|                     |	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  rc  r   r   r<   r=   rY  rX  r  r  r  )r  rO  r  r  safe_value_2r  4privateInverseGetFutureTradeV1EntrustPlanListHistoryr  3privateLinearGetFutureTradeV1EntrustPlanListHistory.privateInverseGetFutureTradeV1OrderListHistory-privateLinearGetFutureTradeV1OrderListHistoryr  privateSpotGetHistoryOrderr  parse_orders)r  r   r  r  r  r  rO  r  r  r  r  r  r  r  orderss                  r  fetch_orderszxt.fetch_ordersp
  s      !!!!!!!!![[((F &tGH#(GK $GG99-QWXXf99-QWXX##FIv>> 	[YYv	6':;;F)##!%!Z!Z[_[f[fgnpv[w[w!x!xxxxxxx!%!Y!YZ^ZeZefmouZvZv!w!wwwwwww	!!!PPQUQ\Q\]dflQmQmnnnnnnnnHH!!tv~~48;K;K!OOPTP[P[\cekPlPlmmmmmmmmHHJ!%!C!CMSY!Z!ZJ.8.D''6!4GI!<<T[[RX=Y=YZZZZZZZZH^ x266w33  >>>r  c                 T  K   |                                   d {V  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<   |r|                     |ddg          }|	dk    r1|                     |                     ||                     d {V }
n| 	                    |                     ||                     d {V }
n|r~|                     |d          }|	dk    r1| 
                    |                     ||                     d {V }
nT|                     |                     ||                     d {V }
n#|	|dk    s|dk    rf|	dk    r0|                     |                     ||                     d {V }
n|                     |                     ||                     d {V }
nd }|                     d|          \  }}|dnd}||d<   |d	k    rT|||d<   ||                     |d          }||d<   |                     |                     ||                     d {V }
n/|                     |                     ||                     d {V }
g }|                     |
d          }||                     |dg           }n|                     |
d          }|                     ||||          S )Nr-   r   r  r  rz   rc  r  rd  r  NOT_TRIGGEREDrU  r<   
UNFINISHEDclosed	TRIGGEREDFILLEDcanceledUSER_REVOCATIONCANCELEDr=   r   rY  rX  r  r  r  r  )r  rO  r  r  safe_bool_2r  r  -privateInverseGetFutureTradeV1EntrustPlanListr  ,privateLinearGetFutureTradeV1EntrustPlanList/privateInverseGetFutureTradeV1EntrustProfitList.privateLinearGetFutureTradeV1EntrustProfitList'privateInverseGetFutureTradeV1OrderList&privateLinearGetFutureTradeV1OrderListr  ru  privateSpotGetOpenOrder	safe_dict	safe_listrv  )r  statusr   r  r  r  r  rO  r  r  r  r  rd  r  r  rw  
resultDicts                    r  fetch_orders_by_statuszxt.fetch_orders_by_status  s     !!!!!!!!![[((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 ',$ "' 	\YYv	':;;F)##!%!S!STXT_T_`gioTpTp!q!qqqqqqq!%!R!RSWS^S^_fhnSoSo!p!ppppppp 	\YYv';<<F)##!%!U!UVZVaVabikqVrVr!s!sssssss!%!T!TUYU`U`ahjpUqUq!r!rrrrrrr!tv~~48;K;K)##!%!M!MdkkZaciNjNj!k!kkkkkkk!%!L!LT[[Y`bhMiMi!j!jjjjjjjJ!%!C!CDY[a!b!bJ.8.D''6!4GI$+0GK($"ii88G',GG$!%!@!@WV\A]A]!^!^^^^^^^!%!=!=dkk'SY>Z>Z![![[[[[[[f ^^Hh77
!^^J<<FF^^Hh77F  >>>r  c                 D   K   |                      d||||           d{V 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  Nr  r  r   r  r  r  s        r  fetch_open_orderszxt.fetch_open_orders  s6      " 00vVVVVVVVVVr  c                 D   K   |                      d||||           d{V 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>`
        r|  Nr  r  s        r  fetch_closed_orderszxt.fetch_closed_orders%  s7      " 0065%QWXXXXXXXXXr  c                 D   K   |                      d||||           d{V 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  Nr  r  s        r  fetch_canceled_orderszxt.fetch_canceled_orders8  s7      " 00VUESYZZZZZZZZZr  c                 8  K   |                                   d{V  d}||                     |          }i }d}d}d}|                     d||          \  }}|                     d||          \  }}|                     |dd          }	|                     |d          }
|	r||d<   n|
r||d<   n||d<   |	r|                     |ddg          }|d	k    r1|                     |                     ||                     d{V }nV| 	                    |                     ||                     d{V }n%|
r||                     |d          }|d	k    r0| 
                    |                     ||                     d{V }n|                     |                     ||                     d{V }n|d	k    r0|                     |                     ||                     d{V }nq|d
k    s|dk    s|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|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  rc  rd  re  rf  r  r   r   r<   r=   r  )r  rO  r  r  rp  r  r  0privateInversePostFutureTradeV1EntrustCancelPlanr  /privateLinearPostFutureTradeV1EntrustCancelPlan6privateInversePostFutureTradeV1EntrustCancelProfitStop5privateLinearPostFutureTradeV1EntrustCancelProfitStop*privateInversePostFutureTradeV1OrderCancel)privateLinearPostFutureTradeV1OrderCancelprivateSpotDeleteOrderOrderIdrD  )r  r-   r   r  rO  r  r  r  r  r  rd  isContractResponser   s                r  cancel_orderzxt.cancel_orderK  sP       !!!!!!!!![[((F99-QWXXf99-QWXX##FIv>>!__V5IJJ 	$#%GK   	$"$GJ!#GI 	^YYv	6':;;F)##!%!V!VW[WbWbcjlrWsWs!t!ttttttt!%!U!UVZVaVabikqVrVr!s!sssssss 	^YYv';<<F)##!%!\!\]a]h]hiprx]y]y!z!zzzzzzz!%![![\`\g\ghoqw\x\x!y!yyyyyyy	!!!LLT[[Y`bhMiMijjjjjjjjHH!!tv~~48;K;K!KKDKKX_agLhLhiiiiiiiiHH!??GU[@\@\]]]]]]]]H,  'd2]]DT\L\.[DOOHhXZ4[4[v...r  c                   K   |                                   d{V  i }d}| |                     |          }|d         |d<   d}d}d}|                     d||          \  }}|                     d||          \  }}|                     |dd          }|                     |d          }	|r|                     |ddg          }|dk    r1|                     |                     ||                     d{V }n|| 	                    |                     ||                     d{V }nK|	r||                     |d          }|dk    r0| 
                    |                     ||                     d{V }n|                     |                     ||                     d{V }n|dk    r0|                     |                     ||                     d{V }n|d	k    s|d
k    s|dk    r0|                     |                     ||                     d{V }nUd}
|                     d|          \  }
}|
dnd}||d<   |                     |                     ||                     d{V }|                     |          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  rc  rd  r   r   r<   r=   rY  rX  r  )r  rO  r  r  rp  r  r  3privateInversePostFutureTradeV1EntrustCancelAllPlanr  2privateLinearPostFutureTradeV1EntrustCancelAllPlan9privateInversePostFutureTradeV1EntrustCancelAllProfitStop8privateLinearPostFutureTradeV1EntrustCancelAllProfitStop-privateInversePostFutureTradeV1OrderCancelAll,privateLinearPostFutureTradeV1OrderCancelAllr  privateSpotDeleteOpenOrder
safe_order)r  r   r  r  rO  r  r  r  r  rd  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 	[YYv	6':;;F)##!%!Y!YZ^ZeZefmouZvZv!w!wwwwwww!%!X!XY]YdYdelntYuYu!v!vvvvvvv 	[YYv';<<F)##!%!_!_`d`k`klsu{`|`|!}!}}}}}}}!%!^!^_c_j_jkrtz_{_{!|!|||||||	!!!OOPTP[P[\cekPlPlmmmmmmmmHH!!tv~~48;K;K!NNt{{[bdjOkOkllllllllHHJ!%!C!CDUW]!^!^J.8.D''6!4GI!<<T[[RX=Y=YZZZZZZZZH* OOH%%
 	
r  idsc                 h  K   |                                   d{V  d|i}d}||                     |          }d}|                     d||          \  }}|t          | j        dz             |                     |                     ||                     d{V }|                     |          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>`
        NorderIdsrC   zV cancelOrders() does not support swap and future orders, only spot orders are accepted)r  rO  r  r"   r-   privateSpotDeleteBatchOrderr  r  )r  r  r   r  r  rO  r  r  s           r  cancel_orderszxt.cancel_orders  s       !!!!!!!!!
 [[((F99.&RXYYtw  *B   B  C  C  C99$++gv:V:VWWWWWWWW 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   rN  r  r   r:   r   createdTimerJ  rw  executedQtyupdatedTimer
  r-   )r  r  cancelIdre  rf  clientOrderIdclientModifyIdr  r  lastTradeTimestamplastUpdateTimestampr  r  r  postOnlyr  r  r{  r  rO  rP  rQ  rR  rS  r  
leavingQtyavgPricerU  r  r  r  )filled	remainingr|  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   rO  r  r  r   r  r	  r  filledQuantityr  lastUpdatedTimestamps               r  rD  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  r|  r  rejectedexpired)NEWPARTIALLY_FILLEDr~  r  REJECTEDEXPIREDr{  rz  
TRIGGERINGr}  r  PLATFORM_REVOCATIONHISTORYr!  r  r  statusess      r  r  zxt.parse_order_status  sO     &""  # !)#- 
 
 &&999r  r  c                   K   |                                   d{V  i }d}||                     |          }|||d<   |||d<   d}d}d}	|                     dd|          \  }}|                     dd|          \  }}|dk    r0|                     |                     ||                     d{V }	nY|dk    s|dk    s|dk    r0|                     |                     ||                     d{V }	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  s      !!!!!!!!!}}T**H#(GK $GG99-vVVf99-vVVi!KKDKKX_agLhLhiiiiiiiiHH!!tv~~48;K;K!JJ4;;W^`fKgKghhhhhhhhHH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-   	directionr1  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  r1  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                   K   |                                   d{V  d}|                     |          \  }}|                     |          }|                     ||          }|                     d|d           |d         |d}|                     |                     ||                     d{V }|                     |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  r7  r  r6  r  r  r  s	            r  fetch_deposit_addresszxt.fetch_deposit_address.  s      !!!!!!!!!"AA&IIV==&&++K>>	$$%:IyQQQ 
 
 ::4;;wPV;W;WXXXXXXXX 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_addressR  sk     "">9==7###"//h??##NF;;
 
 	
r  c                   K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                     d{V }|                     |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_depositsc  s       !!!!!!!!!}}T**H"*4.GJ#(GK $GG::4;;wPV;W;WXXXXXXXX6 x266??4"55&&x5%PPPr  c                   K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                     d{V }|                     |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;;DKKQW<X<XYYYYYYYY6 x266oodGR88&&{HeUFSSSr  r  r  c                 d  K   |                      |           |                                  d{V  |                     |          }|                     ||          \  }}d}|                     |          \  }}|                     | j        di           }|                     ||||          }	|d         |	|                     ||          |d}
|||
d<   | 	                    | 
                    |
|                     d{V }|                     |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  r7  networkIdsByCodesr6  r  r  r  s                r  r   zxt.withdraw  sU      	7###!!!!!!!!!==&&99#vFFV"AA&IIV OODL*bII&&'8+tTRR	 00v>>	
 
 ?!GFO55dkk'66R6RSSSSSSSS 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  r|  rate)commentr  internal)r  r!  r"  r$  r  r#  parse_transaction_status)r  r  r  r  r  r  r  currencyCoder  r  r6  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_statusC  s=       
 
 &&999r  r]  c                   K   |t          | j        dz             |                     |d          }|                     d|dddg           |dk     s|dk    rt	          | j        d	z             |                                  d{V  |                     |          }|d
         st          | j        dz             |d         ||d}d}|                     d||          \  }}d}|dk    r0| 	                    | 
                    ||                     d{V }n/|                     | 
                    ||                     d{V }|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 argumentrN  r   rM  rL  r   }   z3 setLeverage() leverage should be between 1 and 125r   z- setLeverage() supports contract markets onlyr-   )r   rN  r]  r   )r   r-   r!  r  r   r  rO  r   r  4privateInversePostFutureUserV1PositionAdjustLeverager  3privateLinearPostFutureUserV1PositionAdjustLeverage)	r  r]  r   r  rN  rO  r  r  r  s	            r  set_leveragezxt.set_leverageO  s      >#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!VVW[WbWbcjlrWsWsttttttttHH!UUVZVaVabikqVrVrssssssssH r  c                 B   K   |                      ||d|           d{V 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  Nmodify_margin_helperr  r   r  r  s       r  
add_marginzxt.add_margin{  4       ..vvufMMMMMMMMMr  c                 B   K   |                      ||d|           d{V 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>`
        SUBNr+  r-  s       r  reduce_marginzxt.reduce_margin  r/  r  c                   K   |                      |d          }|                     d|dddg           |                                  d {V  |                     |          }|d         |||d}d }|                     d||          \  }}d }	|dk    r0|                     |                     ||                     d {V }	n/|                     |                     ||                     d {V }	|                     |	|          S )	NrN  r   rM  rL  r-   )r   r;   r  rN  modifyMarginHelperr   )	r!  r  r  rO  r  ,privateInversePostFutureUserV1PositionMarginr  +privateLinearPostFutureUserV1PositionMarginparse_margin_modification)
r  r   r  addOrReducer  rN  rO  r  r  r  s
             r  r,  zxt.modify_margin_helper  sF     ''??$$]L.SY[bRcddd!!!!!!!!!V$$Tl(	
 
 99:NPVX^__i!NNt{{[bdjOkOkllllllllHH!MMdkkZaciNjNjkkkkkkkkH --h???r  c                 D    |d d d |                      d |          d d d d d d
S )N)
r
  r  r  r  r   r  r  r0  r  r  )r  )r  r  rO  s      r  r7  zxt.parse_margin_modification  s?    &&tV44
 
 	
r  c                 v  K   |                                   d{V  d}|                     dd|          \  }}d}|dk    r|                     |           d{V }n|                     |           d{V }|                     |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  rE  r  r  r  r  s         r  fetch_leverage_tierszxt.fetch_leverage_tiers  s       !!!!!!!!!99:NPTV\]]i!YYZ`aaaaaaaaHH!XXY_````````H2 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  rE  marketIdKeyr  r/  r0  r  rO  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                   K   |                                   d{V  |                     |          }d|d         i}d}|                     d||          \  }}d}|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |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>`
        Nr   r-   rl   r   r  )r  rO  r  9publicInverseGetFutureMarketV1PublicLeverageBracketDetailr  8publicLinearGetFutureMarketV1PublicLeverageBracketDetailr  rA  )r  r   r  rO  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![[\`\g\ghoqw\x\xyyyyyyyyHH!ZZ[_[f[fgnpv[w[wxxxxxxxxH. 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   bracketrq  r   maxNominalValuemaintMarginRatemaxLeverage)tierr   r  rg  rh  maintenanceMarginRaterL  r
  )	r  r  r   r!  r  rM  r  r  r$  )r  r
  rO  r   bracketsr/  rM  r  s           r  rA  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                   K   |t          | j        dz             |                                  d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S |                     |          }|d	         st          | j        d
z             d|d         i}|||d<   nd|d<   d}|                     d||          \  }}d}	|dk    r0|                     | 	                    ||                     d{V }	n/| 
                    | 	                    ||                     d{V }	|                     |	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   rR  r  r  r  )r   r-   r  r  fetch_paginated_call_cursorrO  r   r  6publicInverseGetFutureMarketV1PublicQFundingRateRecordr  5publicLinearGetFutureMarketV1PublicQFundingRateRecordr  r  r   r!  r  r  rM  r$  r  sort_byfilter_by_symbol_since_limit)r  r   r  r  r  r  rO  r  r  r  r  r  ratesr/  r0  r  symbolInnerr  sorteds                      r  fetch_funding_rate_historyzxt.fetch_funding_rate_historya  s      >#DG.e$efff!!!!!!!!!88AZ\fgg& 	G99:SU[]bdikqswy}  @A  CF  G  G  G  G  G  G  G  G  GV$$f~ 	aDG&__```fTl
 $GG"GG99:SU[]cddi!XXY]YdYdelntYuYuvvvvvvvvHH!WWX\XcXcdkmsXtXtuuuuuuuuH* 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                 >   K   |                      ||           d{V 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>`
        N)fetch_funding_rate)r  r   r  s      r  fetch_funding_intervalzxt.fetch_funding_interval  s0       ,,VV<<<<<<<<<r  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}d}|                     d||          \  }}d}|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |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>`
        Nr<   z0 fetchFundingRate() supports swap contracts onlyr   r-   rb   r   r  )
r  rO  r   r-   r  0publicInverseGetFutureMarketV1PublicQFundingRater  /publicLinearGetFutureMarketV1PublicQFundingRater  parse_funding_rate)r  r   r  rO  r  r  r  r  s           r  r]  zxt.fetch_funding_rate  sC      !!!!!!!!!V$$f~ 	ZDG&XXYYYfTl
 99:LfV\]]i!RRSWS^S^_fhnSoSoppppppppHH!QQRVR]R]^egmRnRnooooooooH 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  rR  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )r!  r  r  r$  r  )r  r   rO  r  r   r  r  s          r  rb  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                 4  K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}|||d<   |||d<   d}|                     d||          \  }}d}|d	k    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |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>`
        Nr<   z3 fetchFundingHistory() supports swap contracts onlyr   r-   r  r  r_   r   r  r  r   r  )r  rO  r   r-   r  3privateInverseGetFutureUserV1BalanceFundingRateListr  2privateLinearGetFutureUserV1BalanceFundingRateListr  r  r   rM  parse_funding_historyrV  filter_by_since_limit)r  r   r  r  r  rO  r  r  r  r  r  r  r/  r0  rZ  s                  r  fetch_funding_historyzxt.fetch_funding_history  s      !!!!!!!!!V$$f~ 	]DG&[[\\\fTl
 #(GK $GG99:OQWY_``i!UUVZVaVabikqVrVrssssssssHH!TTUYU`U`ahjpUqUqrrrrrrrrH, 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   rO  r  r   r1  r  r  s           r  ru  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                   K   |                                   d{V  |                     |          }d|d         i}d}|                     d||          \  }}d}|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |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>`
        Nr   r-   r|   r   r  r   r   positionSizer   )r  rO  r  )privateInverseGetFutureUserV1PositionListr  (privateLinearGetFutureUserV1PositionListr  r  r   r!  r  parse_position)r  r   r  rO  r  r  r  	positionsr/  r0  r  marketInnerr{  s                r  fetch_positionzxt.fetch_positionZ  s      !!!!!!!!!V$$fTl
 99/6SYZZi!KKDKKX_agLhLhiiiiiiiiHH!JJ4;;W^`fKgKghhhhhhhhH4 OOHh;;	q#i..)) 	? 	?AaLE''x88H**8T4LLK++E>BBLs""**5+>>>>> #tr  c                 P  K   |                                   d{V  d}|                     dd|          \  }}d}|dk    r|                     |           d{V }n|                     |           d{V }|                     |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  r|  r}  r  r  r   r!  r  rM  r~  filter_by_array_positions)r  rE  r  r  r  r  r  r/  r0  r  r  s              r  fetch_positionszxt.fetch_positions  s]      !!!!!!!!!99:JDRXYYi!KKFSSSSSSSSHH!JJ6RRRRRRRRH4 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  rN  	contractsr{  rw  
entryPricerf  notionalr]  
collateralinitialMarginmaintenanceMargininitialMarginPercentage)maintenanceMarginPercentageunrealizedPnlliquidationPricer  r   marginRatio)r!  r  r  r$  safe_positionr  r  )r  positionrO  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                   K   |                                   d{V  |                     |          }|                     | j        d          }|                     |||          }|                     |||          }	|                     ||          }
|                                 |d         |
||	d}|                     |                     ||                     d{V }| 	                    ||          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>`
        Nr  r-   )bizIdr  r  fromto)
r  r  r  rW  r!  r  uuidprivateSpotPostBalanceTransferr  parse_transfer)r  r  r  r  r  r  r  accountsByTypefromAccountIdtoAccountIdrE  r  r  s                r  r   zxt.transfer  s
      !!!!!!!!!==&&~FF((kRR&&~y)LL11$??YY[[ "!
 
 <<T[[RX=Y=YZZZZZZZZ ""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                 0  K   |t          | j        dz             |                                  d{V  |                     |          }|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}|                     | 	                    ||                     d{V }|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  ISOLATEDrN  zL setMarginMode() requires a positionSide parameter, either "LONG" or "SHORT"r-   )r  rN  r   )
r   r-   r  rO  r   lowerr   r?  /privateLinearPostFutureUserV1PositionChangeTyper  )r  r  r   r  rO  posSider  r  s           r  set_margin_modezxt.set_margin_mode1  sU      >#DG.[$[\\\!!!!!!!!!V$$&> 	YDG&WWXXX%%''
##
g(=(=TW'iijjj  "JJ#J((@@?#DG.|$|}}}&#Tl
 

 MMdkkZaciNjNjkkkkkkkk r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }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    rd|s|r0| 	                    | 
                    |	|                     d{V }n|                     | 
                    |	|                     d{V }n|s|r0|                     | 
                    |	|                     d{V }nx|                     | 
                    |	|                     d{V }nH|                     ||          |	d<   |                     | 
                    |	|                     d{V }|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 argumentrP  rQ  rR  rS  rf  r  r{  r<   rJ  rJ   r   r	  r  )r   r-   r  rO  r  r  rA  rB  r  6privateInversePostFutureTradeV1EntrustUpdateProfitStopr  *privateInversePostFutureTradeV1OrderUpdate5privateLinearPostFutureTradeV1EntrustUpdateProfitStop)privateLinearPostFutureTradeV1OrderUpdateprivateSpotPutOrderOrderIdr  rD  )r  r-   r   r  r  r  r{  r  rO  r  rP  rR  r`  ra  r  r  r  s                    r  
edit_orderzxt.edit_order`  s6     & >#DG.X$XYYY!!!!!!!!!V$$%%fj:LMM''>RSS
6J#=>>d*
"$. 	F 	F"$GJ!#GI#66vuEEGG&> %	[ N.2.E.Efh.W.W*++'040G0GPZ0[0[,--%)%=%=ff%M%M	"G"==k6SYZZOGV)## s s%)%`%`aealalmtv|a}a}%~%~~~~~~~HH%)%T%TUYU`U`ahjpUqUq%r%rrrrrrrHH  r r%)%_%_`d`k`klsu{`|`|%}%}}}}}}}HH%)%S%STXT_T_`gioTpTp%q%qqqqqqqHH #'":":66"J"JGJ!<<T[[RX=Y=YZZZZZZZZH %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   rV  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   r9  r   r   rC  r<  r=  rG  dictrN  strr  listr  r  r  r   r  r  r  r  r  r  r#  r!  floatr7  r   r   r   r6  r9  r:  rn  rx  r  r  r  r  r  r  r   r  rD  r  r   r
   r  r  r  r   r  r  r   r  r   r   r   r	  r  intr)  r.  r2  r   r,  r7  r   r>  r=  r   rF  rA  r[  r   r^  r]  rb  rw  ru  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: H H H HT *, D DV D D D D* /1 8+ 8+ 8+ 8+t :< A8 A8 A8 A8F  s4 sF s s s sj ?CQUdhqs UJ UJ UJ UJ3 UJ^a UJ UJ UJ UJn$
 $
 $
4 $
 $
 $
 $
L @DB U US U U U U Un 68 H1 H1 H1 H1 H1 H1T 8<B R? R?49 R?7 R? R? R? R?h :>b '4 '4T#Y '4 '4 '4 '4RN N N N` <@d[] C1 C1 C1S C1 C1 C1 C1 C1J 37TX\eg e? e?C e?s e?RU e? e? e? e?Nb b b bH *, I, I, I, I,V+) +) +)Z XZ Q Qc Q Q Q Q Q" mqy{ _ _ _I _Y _X] _fi _ _ _ _@ NRZ\ 4/ 4/c 4/ 4/ 4/ 4/l RV^` @2 @2# @2 @2 @2 @2D 8<B j/ j/C j/ j/ j/ j/ j/X 04$UYbd _? _? _?C _?s _? _? _? _?B BFTXgktv ? ?3 ?c ?ad ? ? ? ?B 59tZ^gi W Wc W WTW W W W W& 7;\`ik Y Y Y3 YVY Y Y Y Y& 9=4^bkm [ [# [S [X[ [ [ [ [& 9=R K/ K/S K/# K/ K/ K/ K/Z 59 G
 G
c G
 G
 G
 G
R AER #
 #
tCy #
# #
TXY^T_ #
 #
 #
 #
Je e e eN: : :$ .2SW`b 9A 9As 9A# 9AS 9Agklwgx 9A 9A 9A 9Av% % % % % %N8 8 8 =? "< "< "<> "< "< "< "<H
 
n 
 
 
 
" 04$UYbd 3Q 3Q 3QC 3Qs 3Q 3Q 3Q 3Qj 37TX\eg 3T 3TC 3Ts 3TRU 3T 3T 3T 3Tj QU]_ )8 )83 )8 )8 )8# )8do )8 )8 )8 )8VI
 I
T I
X I
Q\ I
 I
 I
 I
V
: 
: 
: ?C2 * *3 * * * * *X CE N Ns NE N N N N FH N N# Nu N N N N SU @ @ @Yk @ @ @ @8
 
>P 
 
 
 
 ?C2 ,B ,B$s) ,BR_ ,B ,B ,B ,B\ P]    > EG -> -> ->4P\K] -> -> -> ->^" "\@R " " " "H >BPTcgpr IY IYs IY# IY]` IY IY IY IYV @B 
= 
=3 
=k 
= 
= 
= 
= <> &7 &7s &7+ &7 &7 &7 &7P"
 "
; "
 "
 "
 "
H 9=4^bkm :@ :@# :@S :@X[ :@ :@ :@ :@x
 
 
 
4 8: 7 73 7 7 7 7r :>b 2P 2PT#Y 2PTRZ^ 2P 2P 2P 2Ph1 1 1 1f ac (7 (73 (7 (7C (7TW (7gt (7 (7 (7 (7T
 
 
 
 DHPR - - -S - - - -^ fjx|  FH V0 V03 V0 V09 V0I V0_b V0ru V0  MR V0 V0 V0 V0p@ @ @D  b$T @P @P @P @P @P @P @P @Pr  r*   )0 ccxt.async_support.base.exchanger   ccxt.abstract.xtr   r  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   6 5 5 5 5 5 ( ( ( ( ( (   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  