
    !:hA'                       d dl mZ d dlmZ d dl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 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, d dlm-Z- d dlm.Z. d dl/m0Z0 d dl/m1Z1 d dl2m3Z3  G d dee      Z4y)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyIntMarginModificationMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)OrderImmediatelyFillable)NotSupported)DDoSProtection)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)TRUNCATE)	TICK_SIZE)Precisec                       e Zd Zdef fdZd Zi fdZi fdefdZi fde	fdZ
i fdee   fdZdedefd	Zdefd
Zi fdefdZdi fdededefdZdNdededefdZi fdedefdZdddi fdedededee   fdZdNdedefdZdi fdefdZdi fdedefdZdNdedede fdZ!ddi fdedededee    fdZ"de#fdZ$dNdedede%f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de#fd)Z-dddi fde#dededee%   fd*Z.dddi fde#dededee%   fd+Z/di fd(ede#fd,Z0di fde#fd-Z1dddi fde#dedefd.Z2dddi fd/e#dededee3   fd0Z4dddi fd/e#dededee3   fd1Z5dNd2Z6dNd3ed4e7de3fd5Z8di fd/ed%e'd6ede3fd7Z9dNd4e7fd8Z:di fd9efd:Z;dNd;Z<dddi fd/e#dededee=   fd<Z>i fd/ed%e'd=ed>ede=f
d?Z?di fd@ede#fdAZ@dNdeAfdBZBi fded%e'deAfdCZCdDdEi ddfdFZDd/eEdGedHedIedJedKefdLZFi fdMZG xZHS )Obitruereturnc                    | j                  t        t        |          i ddddddgddd	d
dddddi dd dddd
dddd
dd
dd
dd
dd
dd
dddddd
dd
dddd
d d
i d!dd"d
d#d
d$dd%dd&dd'dd(dd)dd*d
d+d
d,d
d-d
d.d
d/d
d0dd1d
i d2d
d3dd4d
d5dd6d
d7d8d9dd:d
d;d
d<d
d=d
d>d
d?d
d@d
dAd
dBd
dCd
i dDd
dEd
dFd
dGd
dHd
dId
dJd
dKd
dLd
dMd
dNd
dOddPd
dQd
dRd
dSd
dTdi dUddVd
dWd
dXd
dYddZd
d[d
d\dd]dd^d
d_d
d`d
dad
dbd
dcd
ddd
ded
i dfd
dgddhddiddjddkddld
dmd
dnd
dod
dpddqd
drddsd
dtd
dud
dvddd
d
dddwdxdydzd{d|d}d~dddd	dddddddddddgddddddddiidddddddgddgddggdddddddddddddddiddddddddddddddddiddddddiiiddddddddddiiddddddddddddddddddiddddddddddiiddddddddddddddddddiddddd
d| j	                  d      | j	                  d      ddddd| j	                  d      | j	                  d      | j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d«      | j	                  d      g| j	                  dë      | j	                  dī      gg
| j	                  d      | j	                  d      g| j	                  d      | j	                  dū      g| j	                  d      | j	                  dƫ      g| j	                  d      | j	                  dǫ      g| j	                  d      | j	                  dȫ      g| j	                  d      | j	                  dɫ      g| j	                  d      | j	                  dʫ      g| j	                  d      | j	                  d˫      g| j	                  d«      | j	                  d̫      g| j	                  dë      | j	                  d      gg
d͜dΜidddd| j	                  dЫ      | j	                  dȫ      | j	                  d      | j	                  dЫ      g| j	                  d      | j	                  dѫ      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  dҫ      g| j	                  d      | j	                  dҫ      g| j	                  d      | j	                  dҫ      g| j	                  d«      | j	                  dҫ      g| j	                  dë      | j	                  dҫ      gg
| j	                  d      | j	                  dȫ      g| j	                  d      | j	                  dɫ      g| j	                  d      | j	                  dӫ      g| j	                  d      | j	                  dԫ      g| j	                  d      | j	                  d      g| j	                  d      | j	                  dի      g| j	                  d      | j	                  d֫      g| j	                  d      | j	                  d׫      g| j	                  d«      | j	                  dث      g| j	                  dë      | j	                  d٫      gg
d͜dΜidڜddg dܢdd
t
        ddd
d
dddi ddddddddddddddddddddddddddddddddddi dd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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/d0d1d2d3d4d5d6d7d8d9d:d;d<ddydzd{d|d}d~dd=ddd>
d?d@dAdBdCdDdEdFdGdHdIdJdJdIdIdJdKdLdMdNdOidPt        dQd
d
dd d d
d
d dddd
dRd
d
d
ddd
ddSd d
ddTdTddUd
d
d
ddVd
d d
d
ddWd d
ddXddXd
d
ddYdZd[id\	d]d^id^ddd
d
d_dZd`id dad]dbid]dbidcd d dcdddei dft        dgt        dht        dit        djt        dkt        dlt        dmt        dnt        dot        dpt        dqt        drt        dst        dtt        dut        dvt         i dwt        dxt        dyt"        dzt$        d{t        d|t"        d}t"        d~t"        dt"        dt"        dt"        dt"        dt"        dt         dt"        dt"        dt"        i dt"        dt         dt"        dt"        dt"        dt&        dt        dt"        dt"        dt"        dt"        dt         dt         dt        dt        dt(        dt(        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt*        dt"        dt        dt        dt        dt        dt        t        t        t         dd      S (  Nidr.   nameBitrue	countriesSG	rateLimit  	certifiedFversionv1proThasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrdercloseAllPositionsclosePositioncreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrder$createOrderWithTakeProfitAndStopLoss&createOrderWithTakeProfitAndStopLossWscreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeesfetchTransactionsfetchTransfersfetchVolatilityHistoryfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage)	setMarginsetMarginModesetPositionModetransferwithdraw
timeframes1m5m15m30m1H2H4H1D1W)	r   r   r   r   1h2h4h1d1wurlszOhttps://github.com/user-attachments/assets/67abe346-1273-461a-bd7c-42fa32907c8ezhttps://www.bitrue.com/apizhttps://fapi.bitrue.com/fapizhttps://fapi.bitrue.com/dapiz https://www.bitrue.com/kline-api)r>   fapidapiklinezhttps://www.bitrue.comzEhttps://www.bitrue.com/affiliate/landing?cn=600000&inviteCode=EZWETQEz;https://github.com/Bitrue-exchange/bitrue-official-api-docszhttps://www.bitrue.com/api-docsz;https://bitrue.zendesk.com/hc/en-001/articles/4405479952537)logoapiwwwreferraldocfeesr   publicget   )zpublic.jsonzpublic{currency}.jsond   i     
   )costbyLimit(   )r   noSymbol   )pingtimeexchangeInfodepthtradeshistoricalTrades	aggTradeszticker/24hrzticker/pricezticker/bookTickerzmarket/kline)order
openOrders	allOrdersaccountmyTradeszetf/net-value/{symbol}zwithdraw/historyzdeposit/history   )r   zwithdraw/commitr   )r   postdelete)r   privater   r   )r   r:   v2)r   r   	contractsr   tickerklines)r   r   r   r   leverageBracketcommissionRatefutures_transfer_historyforceOrdersHistory)positionMargin
level_editcancelr   allOpenOrdersfutures_transfer)r   r   )r:   r   )r>   r   r   r   z0.00098)feeSide	tierBased
percentagetakermakertradingquotez0.000400z0.00020002502500z0.0003507500z0.00032022500z0.00030050000z0.000270100000z0.000250200000z0.000220400000750000z0.000170z0.000160z0.000140z0.000120z0.000100z0.000080z0.000060z0.000040z0.000020)r   r   )r   r   r   r   r   tiersbasez0.000500z0.000450z0.000240z0.000050z	0.0000030z	-0.000050z	-0.000060z	-0.000070z	-0.000080z	-0.000090)r   rA   deliveryoptionsr>   linearinversev2PrivateGetMyTrades  r   FULL)marketlimitERC20ETHTRC20TRX	AETERNITY	AeternityAIONALGOAlgorandASKATOMAVAXCzAVAX C-ChainBCHBEP2BEP20BitcoinBRP20ADACardano
CASINOCOIN
CasinoCoinzCASINOCOIN-XRPLzCasinoCoin XRPL	CONTENTOS	ContentosDASHDashDECOINDecoinDFI	DeFiChainDGBDIVIDiviDOGEdogecoinEOSETCFILECOINFilecoinFREETONHBARHEDERAzHedera HashgraphHRC20ICONICPIGNISIgnisINTERNETCOMPUTERzInternet ComputerIOTAKAVAKSMLTCLiteCoinLUNALunaMATIC
MOBILECOINzMobile CoinMONACOINMonaCoinXMRMoneroNEMNEP5OMNIPACDOTPolkadotRAVEN	RavencoinSAFEXSafexSOLSOLANASongbirdzStellar LumensSymbolTezosthetaTHETAVeChainWanchainzXinFin NetworkXRPXRPLZIL)SGBXMLXYMXTZrR  rS  VECHAINWANCHAINXINFINrV  rW  rX  12H)
r   r   r   r   r   r   r   12hr   r   1min5min15min30minr   1day1week1month)r   r   r   r   r   r   r   1M)r>   rA   walletcontract)r>   rA   r@   fundingfundrk  )!createMarketBuyOrderRequiresPricer|   fetchMyTradesMethod#hasAlreadyAuthenticatedSuccessfullycurrencyToPrecisionRoundingMode
recvWindowtimeDifferenceadjustForTimeDifferenceparseOrderToPrecisionnewOrderRespTypenetworksdefaultTyper   accountsByTypecommonCurrenciesMIMz	MIM SwarmprecisionModefeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventionicebergi )r  r  daysBack	untilDayssymbolRequired)r  triggerr  r  )r  r  r  r  r  Z   )r  r  r  daysBackCanceledr  r  r  r  r  i  )	sandboxrN   createOrdersr   r   r   r   r]   r   extendsdefault)r  r  r  r  i,  )r  rN   r   r]   forDerivatives)r   r  )r  r>   r  r@   rA   
exceptionszSystem is under maintenance.zSystem abnormalityz/You are not authorized to execute self request.zAPI key does not existz Order would trigger immediately.z%Stop price would trigger immediately.z'Order would immediately match and take.z6Account has insufficient balance for requested action.z Rest API trading is not enabled.zYou don't have permission.zMarket is closed.z*Too many requests. Please try again later.z-1000z-1001z-1002z-1003z-1013z-1015z-1016z-1020z-1021z-1022z-1100z-1101z-1102z-1103z-1104z-1105z-1106z-1111z-1112z-1114z-1115z-1116z-1117z-1166z-1118z-1119z-1120z-1121z-1125z-1127z-1128z-1130z-1131z-1160z-1156z-2008z-2010z-2011z-2013z-2014-2015z-2017z-2019z-3005z-3006z-3008z-3010z-3015z-3022z-4028z-3020z-3041z-5013z-11008z-4051)zInsufficient account balancezhas no operation privilegeMAX_POSITION)exactbroad)deep_extendsuperr.   describeparse_numberr*   r+   r(   r   r   r   r#   r    r'   r%   r&   r!   r   r)   r   r"   r   )self	__class__s    S/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/bitrue.pyr  zbitrue.describe%   s9   fd < > @
A
(@
A
H@
A
 $@
A
 	@
A

 @
A
 t@
A
 4@
A
  lll %l 	l
 %l %l Ul $Ul 'l l "4l tl $Ul  l /l  ,U!l" 0#l$ t%l& 7'l( 9%)l* (+l, '-l. (/l0 "41l2 3l4  5l6 &u7l8 "59l: +E;l< )%=l> #E?l@ ,UAlB $TClD 'ElF (GlH "4IlJ &uKlL  MlN +EOlP *:QlR +DSlT &uUlV 'WlX (YlZ #E[l\ *5]l^ $U_l` ualb "5cld *5elf +Eglh )%ilj  kll !%mln %eolp $Uqlr &uslt -eulv /wlx "5ylz #E{l| +E}l~ l@ !%AlB "5ClD &uElF +EGlH  IlJ dKlL $UMlN +EOlP %eQlR "4SlT uUlV #EWlX dYlZ !$[l\ u]l^  _l` 'alb $Ucld !%elf (glh %eilj )%kll )%mln tolp tqlr slt Tulv twlx "5ylz #E{l| '}l~ $Ul@ !$AlB )%ClD #DElF GlH #EIlJ &uKlL tMlN "!&#(  Wl@
A
l 
m@
A
B i8::?	 0cQ5 VC@
A
b  !!/09:$# "()()0123#qCQR8VZ\^U_@`)a*+45-.89r/J9:0J>?Q5O01$#" *+./-.+,56B,G:;4534	$ *+34%
 !('$!#J "! *A$$[4n !!()()-.)**+*+$	# ",-./)*+,3423<=67	$ 34./*+)*1245%$#L !!()()-.)**+*+$	# ",-./)*+,3423<=67	$ 34./*+)*1245%$#u~c@
A
` $!&"&!..y9!..y9 #*%)&*!%!2!2:!>!%!2!2:!> "&!2!23!79J9J:9V W!%!2!25!94;L;LZ;X Y!%!2!26!:D<M<Mj<Y Z!%!2!26!:D<M<Mj<Y Z!%!2!27!;T=N=Nz=Z [!%!2!27!;T=N=Nz=Z [!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \& "&!2!23!79J9J:9V W!%!2!25!94;L;LZ;X Y!%!2!26!:D<M<Mj<Y Z!%!2!26!:D<M<Mj<Y Z!%!2!27!;T=N=Nz=Z [!%!2!27!;T=N=Nz=Z [!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPS>T U&"  "H #)%)&*!%!2!2:!>!%!2!2:!> "&!2!23!79J9J:9V W!%!2!25!94;L;LZ;X Y!%!2!26!:D<M<Mj<Y Z!%!2!26!:D<M<Mj<Y Z!%!2!27!;T=N=Nz=Z [!%!2!27!;T=N=Nz=Z [!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \& "&!2!23!79J9J:9V W!%!2!25!94;L;LZ;X Y!%!2!26!:D<M<Mj<Y Z!%!2!26!:D<M<Mk<Z [!%!2!27!;T=N=Ns=S T!%!2!27!;T=N=N{=[ \!%!2!28!<d>O>OP[>\ ]!%!2!28!<d>O>OP[>\ ]!%!2!28!<d>O>OP[>\ ]!%!2!28!<d>O>OP[>\ ]&"  "WNa@
A
@ 59! (>7<3;&"#+0).$#%@U@U@  @ F	@
 J@ 5@ F@ ^@ 5@ F@ W@ y@ W@ 9@ !,@  &'8!@"  #@$ F%@& h'@( ;)@* 5+@, F-@. J/@0 51@2 53@4 
5@6 y7@8 F9@: 0;@< W=@> F?@@ 5A@B WC@D '(;E@F FG@H FI@J 5K@L :M@N FO@P WQ@R !-S@T 
U@V 8W@X 5Y@Z F[@\ F]@^ 5_@` :a@b [c@d We@f 8g@h &+#"$$( *. " @B  & #"$$"""$"" %$&&"$%&	2 %(&'$ *#[uA@
A
l {!m@
A
r Ys@
A
t $&+(,,0,0).+06:#'#'"&#(	( #($)$)26+//4#')$, %)&+!%$*%+*.& ',#($)*.	# ',!%#($)*.( $(&+!%$&,-%'#($)*.	*  #q;z y  )&*$(27+0	$  # *.# "#3 "#3 	 ##kYu@
A
h D2MD(-D FGWD -.A	D
 78PD <=UD >?WD MN_D 78LD 12BD ()=D A.D 1D 1D 0D  .!D" \#D$ .%D& 1'D( Z)D* \+D, 0-D. Z/D0 Z1D2 Z3D4 Z5D6 Z7D8 Z9D: Z;D< Z=D> \?D@ ZADB ZCDD ZEDF ZGDH \IDJ ZKDL ZMDN ZODP YQDR 0SDT ZUDV ZWDX ZYDZ Z[D\ \]D^ \_D` 0aDb ]cDd ]eDf ]gDh 0iDj 0kDl .mDn .oDp .qDr .sDt .uDv ]wDx ]yDz -{D| Z}D~ .D@ .ADB .CDD /EDF .GDL 5F2B$0MKi@
A
 @
 @
	    c                 B    | j                         | j                  d   z
  S )Nrs  )millisecondsr   )r  s    r  noncezbitrue.nonce  s       "T\\2B%CCCr  c                    K   | j                  |       d{   }t        |j                               }t        |      }|rdnd}|ddd|dS 7 6w)ae  
        the latest known information on the availability of the exchange API

        https://github.com/Bitrue-exchange/Spot-official-api-docs#test-connectivity

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
        Nmaintenanceok)statusupdatedetaurlinfo)spotV1PublicGetPinglistkeyslen)r  paramsresponser  
keysLengthformattedStatuss         r  fetch_statuszbitrue.fetch_status  s]      11&99 HMMO$Y
+5-4%
 	
 :s   AA7Ac                 d   K   | j                  |       d{   }| j                  |d      S 7 w)ah  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://github.com/Bitrue-exchange/Spot-official-api-docs#check-server-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        N
serverTime)spotV1PublicGetTimesafe_integer)r  r  r  s      r  
fetch_timezbitrue.fetch_time  s5      11&99   <88 :s   0.0c                   K   | j                  |       d{   }i }| j                  |dg       }t        dt        |            D ]   }||   }| j	                  |d      }| j	                  |d      }| j                  |      }	| j                  |dg       }
i }t        dt        |
            D ]  }|
|   }| j	                  |d      }| j                  ||	      }|||| j                  |d      | j                  |d	      d| j                  |d
      dd| j                  |d      | j                  |d      did	||<    | j                  |||	d|ddd|dddddddid      ||	<   # |S 7 Uw)z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Ncoinsr   coincoinFulNamechainDetailchainenableDepositenableWithdrawwithdrawFeer   minWithdrawmaxWithdrawminmax)	r  r1   networkdepositr   activefee	precisionlimitscrypto)r1   r2   coder  r  r  r  r   rw  r  r   typer  )
spotV1PublicGetExchangeInfo	safe_listranger  safe_stringsafe_currency_codenetwork_id_to_code	safe_boolsafe_numbersafe_currency_structure)r  r  r  resultr  icurrencyr1   r2   r  networkDetailsrw  jentry	networkIdr  s                   r  fetch_currencieszbitrue.fetch_currencies  s     99&AA^ x"5q#e*% .	AQxH!!(F3B##Hm<D**2.D!^^HmRHNH1c.12 &q) ,,UG<	11)TB!#&#~~e_E $u6F G"++E=A!%"#'#3#3E=#I#'#3#3E=#I%%!	(  77!  $ ##!9 F4L7.	^ A Bs   E/E,EE/c                 .  K   g }| j                  | j                  dg d      }t        dt        |            D ]  }||   }|dk(  r!|j	                  | j                  |             .|dk(  r!|j	                  | j                  |             T|dk(  r!|j	                  | j                  |             zt        | j                  dz   |z   dz          t        j                  |  d	{   }| j                  | j                  |d      d
g       }| j                  |d      }| j                  |d      }	|}
| j                  |
|      }
| j                  |
|	      }
| j                  d   r| j                          d	{    | j                  |
      S 7 7 w)a  
        retrieves data on all markets for bitrue

        https://github.com/Bitrue-exchange/Spot-official-api-docs#exchangeInfo_endpoint
        https://www.bitrue.com/api-docs#current-open-contract
        https://www.bitrue.com/api_docs_includes_file/delivery.html#current-open-contract

        :param dict [params]: extra parameters specific to the exchange api endpoint
        :returns dict[]: an array of objects representing market data
        r|   r   r   r>   r   r  z+ fetchMarkets() self.options fetchMarkets "z " is not a supported market typeNsymbolsr   r   rt  )
safe_valuer   r  r  appendr  fapiV1PublicGetContractsdapiV1PublicGetContractsr   r1   asynciogatherarray_concatload_time_differenceparse_markets)r  r  promisesRawr|   r  
marketTypepromisesspotMarketsfutureMarketsdeliveryMarketsmarketss              r  fetch_marketszbitrue.fetch_markets>  s     t||^Ebcq#l+, 		OA%aJV#""4#C#CF#KLx'""4#@#@#HIy(""4#@#@#HI#DGG.[$[^h$h  lN  %N  O  O		O !55oodooh&BIrR!4//(A6##G];##G_=B <<12++---!!'**S 6P .s%   C%F'F(BF;F<FFr  c                    | j                  |d      }| j                  |d      }| j                  |d      }d }d }d }|d}nd}|dk(  }|dk(  }|dk7  }| j                  |d      }	| j                  |d      }
d }d }|rM|j                  d	      }| j                  |d      }	| j                  |d
      }
|r|
}n|	}| j	                  |      }| j	                  |	      }| j	                  |
      }|dz   |z   }||d|z   z  }| j                  |dg       }| j                  |d      }| j                  |d      }| j                  |di       }| j                  |di       }| j                  |d      }| j                  |d      }| j                  |d|      }| j                  |d|      }| j                  |d      }| j                  |d      }|| j                  |d      }| j                  |d      }|| j                  |d      }i d|d|d|d|d|d|d |	d!|
d"|d#|d|dk(  d$d%d|d&d%d'd%d(|d)k(  d*|||| j                  t        j                  |            d d d d | j                  | j                  |            | j                  | j                  |            d+d d d,| j                  |d-      |d,| j                  |d.      | j                  |d/      d,|d d,d0d |d1S )2Nsymbolsider>   r@   r   r   	baseAsset
quoteAsset-r   /:filters
filterTyper  PRICE_FILTERLOT_SIZEpricePrecisionquantityPrecision
priceScalevolumeScale
multipliermaxQtymaxValidOrderminValminOrderMoneyr1   lowercaseIdr   r   settlebaseIdquoteIdsettleIdr  r?   FrA   rB   r  TRADINGrk  )amountpricer  minQtyminPricemaxPrice)r  r  r  r   )r   r  contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr  )r  safe_string_lowerr  splitr  r  index_by	safe_dictr  r  r,   
string_absparse_precision)r  r  r1   r  r  r  isLinear	isInverse
isContractr  r  r  r  symbolSplitr   r   r  r  filtersByTyper  priceFilteramountFilterdefaultPricePrecisiondefaultAmountPrecisionr	  amountPrecisionr  maxQuantityminCosts                                r  parse_marketzbitrue.parse_market  s   fh/,,VX>  0	<DD	HIfn
!!&+6""6<8((3-K%%k15F&&{A6G"!,,X6F&&v.''0e#cFl"F..B7g|<!!&(3nn]NBG~~mZD $ 0 09I J!%!1!1&:M!N))+|EZ[**<H^_%%fl;
&&|X>**6?CK""<:?&&v?G1
"1
;1
 f1
 D	1

 U1
 f1
 f1
 w1
 1
 D1
 TV^1
 e1
 J1
 e1
 e1
  v*!1
" 
#1
$   --g.@.@.LM"++D,@,@,QR**4+?+?+OP  
  ++L(C&
  ++KD++KD
 #$ a1
 1	
r  c                    d|i}| j                  |d      }| j                  |ddg       }t        dt        |            D ]l  }||   }| j	                  |dd      }| j                  |      }| j                         }	| j	                  |dd	      |	d<   | j	                  |d
d      |	d<   |	||<   n ||d<   | j                  |      |d<   | j                  |      S )Nr  
updateTimebalancesr   r   asset
marginCoinfreeaccountNormallockedaccountLockused	timestampdatetime)	r  safe_value_2r  r  safe_string_2r  r   iso8601safe_balance)
r  r  r  r@  r8  r  balance
currencyIdr  r   s
             r  parse_balancezbitrue.parse_balance  s    ` H
 %%h=	$$Xz9bIq#h-( 	#AqkG++GWlKJ**:6DllnG"00&/RGFO"00(MRGFO"F4L	# ({!\\)4z  ((r  c                   K   | j                          d{    d}| j                  dd|      \  }}d}| j                  dd|      \  }}d}d}|dk(  ra|2|dk(  r-| j                  |       d{   }| j	                  |di       }nH| j                  |       d{   }| j	                  |di       }n| j                  |       d{   }|}| j                  |      S 7 7 s7 H7 w)a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://github.com/Bitrue-exchange/Spot-official-api-docs#account-information-user_data
        https://www.bitrue.com/api-docs#account-information-v2-user_data-hmac-sha256
        https://www.bitrue.com/api_docs_includes_file/delivery.html#account-information-v2-user_data-hmac-sha256

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'future', 'delivery', 'spot', 'swap'
        :param str [params.subType]: 'linear', 'inverse'
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrU   r@   r  data)load_marketshandle_market_type_and_paramshandle_sub_type_and_paramsdapiV2PrivateGetAccountr&  fapiV2PrivateGetAccountspotV1PrivateGetAccountrH  )r  r  r  subTyper  r  s         r  fetch_balancezbitrue.fetch_balanceC  s     !!!99.$PVWf99.$PVW6>"w)';!%!=!=f!EE&"=@ "&!=!=f!EE&"=@ "99&AAHF$ !!&))} 	" FB FB BsF   C)C!AC)/C#0,C)C%,C)	C'
C)#C)%C)'C)Nr  r  c                   K   | j                          d{    | j                  |      }d}|d   rsd|d   i}||dkD  rd}||d<   |d   r*| j                  | j                  ||             d{   }n|d   r| j	                  | j                  ||             d{   }n\|d	   r?d
|d   i}||dkD  rd}||d<   | j                  | j                  ||             d{   }nt        | j                  dz         | j                  |dd      }| j                  |||      }| j                  |d      |d<   |S 7 )7 7 7 aw)a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://github.com/Bitrue-exchange/Spot-official-api-docs#order-book
        https://www.bitrue.com/api-docs#order-book
        https://www.bitrue.com/api_docs_includes_file/delivery.html#order-book

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        Nr@   contractNamer1   r   r  r   r  r>   r  r7   z0 fetchOrderBook only support spot & swap marketsr   lastUpdateIdr  )rK  r  fapiV1PublicGetDepthextenddapiV1PublicGetDepthspotV1PublicGetDepthr$   r1   safe_integer_2parse_order_bookr  )	r  r  r  r  r  r  requestr@  	orderbooks	            r  fetch_order_bookzbitrue.fetch_order_book  sw     !!!V$&>tG  3;E#( h!%!:!:4;;wPV;W!XX	"!%!:!:4;;wPV;W!XXF^&,G  4< E#( !66t{{7F7STTHtww)[[\\4 ''&.I	))(FIF	!..xH	'm 	" YX UsH   ED?AE1E2.E E!AE$E%AEEEEr   c           	         | j                  d |      }| j                  |dd      }| j                  |d      }d }|d   r't        j                  | j                  |d      d      }n| j                  |d      }| j                  i d|d	|d
| j                  |      d| j                  |dd      d| j                  |dd      d| j                  |dd      d| j                  |d      d| j                  |dd      d| j                  |d      d| j                  |d      d| j                  |d      d|d|dd d| j                  |d       d!|d"d | j                  |d#d$      | j                  |d%      |d&|      S )'N	lastPricelastr   r@   rose100priceChangePercentr  r@  rA  high	highPricelowlowPricebidbidPricebuy	bidVolumebidQtyaskaskPricesell	askVolumeaskQtyvwapweightedAvgPriceopen	openPriceclosepreviousClosechangepriceChanger   averagevolumevolquoteVolume)
baseVolumer~  r  )safe_symbolrC  r  r,   
string_mulr  safe_tickerrD  )r  r   r  r  ra  r@  r   s          r  parse_tickerzbitrue.parse_ticker  s   H !!$/!!&+v>%%ff5	
&> ++D,<,<VV,LeTJ))&2FGJ !
f!
!
 Y/!
 D&&v{FC	!

 4%%fj%@!
 4%%fj%@!
 ))&(;!
 4%%fj&A!
 ))&(;!
 D$$V-?@!
 D$$V[9!
 T!
 D!
 T!
 d&&v}=!
  *!!
" t#!
$ ,,VXuE++FMB)!
* + 	r  c                 2  K   | j                          d{    | j                  |      }d}d}|d   rgd|d   i}|d   r*| j                  | j                  ||             d{   }n.|d   r)| j	                  | j                  ||             d{   }|}na|d   rDd|d   i}| j                  | j                  ||             d{   }| j                  |d	i       }nt        | j                  d
z         | j                  ||      S 7 7 7 ~7 Hw)ar  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://github.com/Bitrue-exchange/Spot-official-api-docs#24hr-ticker-price-change-statistics
        https://www.bitrue.com/api-docs#ticker
        https://www.bitrue.com/api_docs_includes_file/delivery.html#ticker

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr@   rT  r1   r   r  r>   r  r   z- fetchTicker only support spot & swap markets)
rK  r  fapiV1PublicGetTickerrW  dapiV1PublicGetTickerspotV1PublicGetTicker24hrr&  r$   r1   r  r  r  r  r  r  rJ  r\  s          r  fetch_tickerzbitrue.fetch_ticker8  s+     !!!V$&>tG h!%!;!;DKKQW<X!YY	"!%!;!;DKKQW<X!YYDF^&,G ";;DKKQW<XYYH>>(Ar2Dtww)XXYYN   v..w 	" ZY ZsG   DDAD%D&.DD7DDADDDDr   sincec                 |  K   | j                          d{    | j                  |      }| j                  | j                  di       }d}d}	|d   r| j                  |di       }
|d   | j	                  |
|d      d}|||d<   |d	   r*| j                  | j                  ||             d{   }n.|d
   r)| j                  | j                  ||             d{   }|}	n|d   r| j                  |di       }|d   | j	                  ||d      d}|||d<   | j                  |d      }|| j                  |d      }||d<   | j                  | j                  ||             d{   }| j                  |dg       }	nt        | j                  dz         | j                  |	||||      S 7 7 7 7 Mw)aT  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://www.bitrue.com/api_docs_includes_file/spot/index.html#kline-data
        https://www.bitrue.com/api_docs_includes_file/futures/index.html#kline-candlestick-data

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch transfers for
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr   r@   rA   r1   rb  )rT  intervalr  r   r  r>   r   )r  scaleuntilfromIdxrJ  z, fetchOHLCV only support spot & swap markets)rK  r  r&  r   r  fapiV1PublicGetKlinesrW  dapiV1PublicGetKlinesr  omitspotV1PublicGetMarketKliner  r$   r1   parse_ohlcvs)r  r  	timeframer  r  r  r  r   r  rJ  timeframesFuturer\  timeframesSpotr  s                 r  fetch_ohlcvzbitrue.fetch_ohlcv  s     !!!V$^^DLL,C
&>#~~j(BG &t ,,-=y&QG
  #( h!%!;!;DKKQW<X!YY	"!%!;!;DKKQW<X!YYDF^!^^JCN ,)).)TJG
  #( %%fg6E 673%*	"!<<T[[RX=YZZH>>(FB7Dtww)WWXXB   vy%GGI 	" ZY [sH   F<F2BF<.F5/.F<F8BF<,F:-AF<5F<8F<:F<c           
         | j                  |d      }|| j                  |d      }|| j                  |dd      | j                  |dd      | j                  |dd      | j                  |d	d
      | j                  |dd      gS )Nr  idxoru  hre  lrg  crw  vr}  )safe_timestampr  safe_number_2)r  ohlcvr  r@  s       r  parse_ohlcvzbitrue.parse_ohlcv  s    2 ''s3	))%7Iuc62uc62uc51uc73uc51
 	
r  r  c                 d  K   | j                          d{    | j                  |dd      }| j                  |d      }| j                  |      }d}|d   red|d   i}|d   r*| j	                  | j                  ||             d{   }n}|d   rx| j                  | j                  ||             d{   }nN|d	   r1d
|d   i}| j                  | j                  ||             d{   }nt        | j                  dz         i }|||d   <   | j                  ||      S 7 7 7 t7 @w)ap  
        fetches the bid and ask price and volume for multiple markets

        https://github.com/Bitrue-exchange/Spot-official-api-docs#symbol-order-book-ticker
        https://www.bitrue.com/api-docs#ticker
        https://www.bitrue.com/api_docs_includes_file/delivery.html#ticker

        :param str[]|None symbols: unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        NFr   r@   rT  r1   r   r  r>   r  z/ fetchBidsAsks only support spot & swap markets)rK  market_symbolsr  r  r  rW  r  spotV1PublicGetTickerBookTickerr$   r1   parse_tickers)r  r  r  firstr  r  r\  rJ  s           r  fetch_bids_askszbitrue.fetch_bids_asks  sG     !!!%%gtU;  !,U#&>tG h!%!;!;DKKQW<X!YY	"!%!;!;DKKQW<X!YYF^&,G "AA$++gW]B^__Htww)ZZ[[2 %VD\!!$00] 	" ZY
 `sF   D0D'A1D0D*	.D07D,85D0-D..:D0*D0,D0.D0c                    K   | j                          d{    | j                  |      }d}d}i }d}|| j                  |d      }| j                  |      }|d   rt	        | j
                  dz         |d   r,| j                  | j                  ||             d{   }|}nvt	        | j
                  dz         | j                  dd|      \  }}|dk7  rt	        | j
                  dz         | j                  | j                  ||             d{   }|}i }	t        dt        |            D ]>  }
| j                  ||
i       }| j                  | j                  |d	            }||	|d
   <   @ | j                  |	|      S 7 q7 7 uw)a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://github.com/Bitrue-exchange/Spot-official-api-docs#24hr-ticker-price-change-statistics
        https://www.bitrue.com/api-docs#ticker
        https://www.bitrue.com/api_docs_includes_file/delivery.html#ticker

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r@   zK fetchTickers does not support swap markets, please use fetchTicker insteadr>   z. fetchTickers only support spot & swap marketsr   z; fetchTickers only support spot when symbols are not provedr  r1   )rK  r  r  r  r$   r1   r  rW  rL  r  r  r&  safe_marketr  )r  r  r  r  rJ  r\  r  r  r  tickersr  r   s               r  fetch_tickerszbitrue.fetch_tickers7  s     !!!%%g.$$Wa0E[['Ff~"477-z#z{{!%!?!?GU[@\!]]"477-]#]^^==ndTZ[LD&v~"477-j#jkk!;;DKKQW<XYYHDT q#d)$ 	+A^^D!R0F%%d&6&6vx&HIF$*GF4L!	+ !!'733I 	" ^ Zs6   FFBFF
 A6FFA1F
FFtradec                 |   | j                  |dd      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  ||      }| j                  |d      }| j                  |dd	      }	d }
| j	                  |d
      }| j	                  |d      }||rdnd}
||rdnd}
d }d|v r5| j                  |dd      | j                  | j                  |d            d}d }| j	                  |d      }||rdnd}| j                  ||| j                  |      ||	|d |
|||d |d|      S )Nctimer   r  qtyr  rT  orderIdr1   tradeIdisBuyerMakerisBuyerrp  rk  
commissionr  commissionAssert)r   r  isMakerr   r   )r  r@  rA  r  r1   r   r  r  takerOrMakerr  r  r   r  )rZ  r  rC  r  r  r  
safe_traderD  )r  r  r  r@  priceStringamountStringmarketIdr  r  r1   r  
buyerMakerr  r  r  r  s                   r  parse_tradezbitrue.parse_trade  s   b ''w?	&&ug6''u5%%eX~F!!(F3""5)4tY7^^E>:
..	2!'6UD#5D5 **5,F 33D4D4DUL^4_`C ..	2&-77L"Y/( " 
  	r  c                 :  K   | j                          d{    | j                  |      }d}|d   r8d|d   i}|||d<   | j                  | j                  ||             d{   }nt	        | j
                  dz         | j                  ||||      S 7 7 3w)a4  
        get the list of most recent trades for a particular symbol

        https://github.com/Bitrue-exchange/Spot-official-api-docs#recent-trades-list

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr>   r  r1   r  z& fetchTrades only support spot markets)rK  r  spotV1PublicGetTradesrW  r$   r1   parse_trades)r  r  r  r  r  r  r  r\  s           r  fetch_tradeszbitrue.fetch_trades  s      !!!V$&>&,G  #( !77GV8TUUHtww)QQRR   65%@@7 	" Vs"   BBAB%B&2BBr  c           
      @    dddddddddd	}| j                  |||      S )Nru  closedcanceled	cancelingrejectedexpired)	INITPENDING_CREATENEWPARTIALLY_FILLEDFILLEDCANCELEDPENDING_CANCELREJECTEDEXPIRED)r  )r  r  statusess      r  parse_order_statuszbitrue.parse_order_status  s;    $ &")" 

 &&99r  r   c                 T   | j                  | j                  |dd            }| j                  |d      }| j                  ||      }| j                  |d      }d }d }d|v r| j	                  |d      }n[d|v r| j	                  |d      }nDd|v r@|dk(  r;t        j                  |d	      r| j	                  |d      }n| j	                  |d      }| j                  |d
      }	| j                  |d      }
| j                  |d      }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dg       }| j                  |d      }| j                  |d      }|dk(  xs |dk(  xs |dk(  }|dk(  rd}| j                  | j                  | j                  |d                  }| j                  i d|d|d|d|d| j                  |      d|d|d|d|d|d|d|
d |d!|d"|d#|	d$|d |d |d%|      S )&Nr  orderStatusr  executedQtyr   transactTimer7  ru  r   avgPricer  origQtycummulativeQuoteQtycumQuoter  r  r  fillsclientOrderIdr  limit_makerGTX	post_onlyr  	stopPricer  r1   r@  rA  lastTradeTimestamppostOnlyr  r  r   r{  filled)	remainingr  r  r   )r  rC  r  r  r  r,   	string_gtr#  r  r  	omit_zero
safe_orderrD  )r  r   r  r  r  r  r  r@  r  r{  r  r  r   r1   r  r  r  r  r  r  r  s                        r  parse_orderzbitrue.parse_order  s   n ((););E8])[\##E84!!(F3!!%7	!U?))%8Iu$))%@IU"$$VS1)-):):5,)O& $ 1 1% FI""5*5  0!!%3 !!%)>
KeY/%%eV4%%eV4ugr2((@&&um<M)]{e/C]Q\I\= D((8H8HP[8\)]^  
E 
" 
 ] 
 	 

 Y/ 
 !"4 
 f 
 D 
 ; 
  
 D 
 U 
 L 
 f 
 D 
  w! 
" f# 
$ + 
, - 	r  r   c                    K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d<   | j	                  |dd|d|       d{   S 7 U7 w)aD  
        create a market buy order by providing the symbol and cost

        https://www.bitrue.com/api-docs#new-order-trade-hmac-sha256
        https://www.bitrue.com/api_docs_includes_file/delivery.html#new-order-trade-hmac-sha256

        :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 swap orders onlyFrn  r  rk  )rK  r  r$   r1   create_order)r  r  r   r  r  s        r  !create_market_buy_order_with_costz(bitrue.create_market_buy_order_with_cost  sy      !!!V$f~tww)ddee6;23&&vxdFSSS 	"
 Ts"   A0A,AA0'A.(A0.A0r  r  r  r  c                   K   | j                          d{    | j                  |      }d}d}	|j                         }
|j                         |
d}|
dk(  r/|t        | j                  dz         | j                  ||      |d<   |d   r|
dk(  }| j                  |d      }| j                  |d|      }|rd	|d
<   n|dk(  rd|d
<   n
|dk(  rd|d
<   |d   |d<   d}| j                  |ddd      \  }}|r|dk(  r|r| j                  |d      }| j                  |d      }||t        | j                  dz         | j                  |      }| j                  |      }t        j                  ||      }||n|}| j                  ||      |d<   | j                  ||      |d<   n(| j                  |      |d<   | j                  |      |d<   d|d<   | j!                  |dd      }|rdnd|d<   | j                  |d d!      }| j                  |      |d <   | j                  |g d"      }|d#   r*| j#                  | j%                  ||             d{   }n.|d$   r)| j'                  | j%                  ||             d{   }| j)                  |d%i       }	n|d&   r|d   |d'<   | j+                  ||      |d(<   | j-                  |d)   d*      }| j/                  |
|      s!t        | j                  d+z   |z   d,z   |z         | j1                  |d-d.      }|| j                  |d-d.g      }||d-<   | j!                  |d/d0      }|)| j                  |d/d0g      }| j                  ||      |d0<   | j3                  | j%                  ||             d{   }|}	nt5        | j                  d1z         | j7                  |	|      S 7 7 x7 L7 :w)2a(  
        create a trade order

        https://www.bitrue.com/api_docs_includes_file/spot/index.html#new-order-trade
        https://www.bitrue.com/api_docs_includes_file/futures/index.html#new-order-trade-hmac-sha256

        :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 currency you want to trade in units of 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.triggerPrice]: *spot only* the price at which a trigger order is triggered at
        :param str [params.clientOrderId]: a unique id for the order, automatically generated if not sent
        :param decimal [params.leverage]: in future order, the leverage value of the order should consistent with the user contract configuration, default is 1
        :param str [params.timeInForce]: 'fok', 'ioc' or 'po'
        :param bool [params.postOnly]: default False
        :param bool [params.reduceOnly]: default False
 EXCHANGE SPECIFIC PARAMETERS
        :param decimal [params.icebergQty]:
        :param long [params.recvWindow]:
        :param float [params.cost]: *swap market buy only* the quote quantity that can be used alternative for the amount
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        N)r  r  LIMITz( createOrder() requires a price argumentr  r@   MARKETr  	POST_ONLYr  fokr  iocr~  r1   rT  TrN   rn  rk  r   a   createOrder() requires the price argument with swap market buy orders to calculate total order cost(amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options["createMarketBuyOrderRequiresPrice"] = False to supply the cost in the amount argument(the exchange-specific behaviour)r  r|  r   positionType
reduceOnlyreduce_onlyCLOSEOPENru  r  1)r  r  r  r  r   r  rJ  r>   r  quantityr  
orderTypes z% is not a valid order type in market newClientOrderIdr  r  r  z- createOrder only support spot & swap markets)rK  r  upperr!   r1   price_to_precisionr#  is_post_onlyhandle_option_and_paramsr  r  number_to_stringr,   r  cost_to_precisionparse_to_numericrB  fapiV2PrivatePostOrderrW  dapiV2PrivatePostOrderr&  amount_to_precisionr  in_arrayrC  spotV1PrivatePostOrderr$   r  )r  r  r  r  r  r  r  r  r  rJ  uppercaseTyper\  isMarketr  r  rn  r   r  r  quoteAmountrequestAmountr  r  validOrderTypesr  r  s                             r  r  zbitrue.create_order  s<    2 !!!V$

JJL!
 G#}"477-W#WXX#66vuEGG&>$0H00GK((4@H"-%"'%"'&,TlGN#04-8<8U8UV\^k  nQ  SW  9X5-vTU]0Q''7662=T\&tww  2R  (R  S  S#'#8#8#@L"&"7"7">K")"4"4\;"OK-1-=DKM(,(>(>v}(UGH%(,(>(>v}(UGH%$($9$9&$A!$($9$9&$A!&'GN#**6<OJ)3gGFO''
C@H"&"7"7"AGJYYv'_`Fh!%!<!<T[[RX=Y!ZZ	"!%!<!<T[[RX=Y!ZZ>>(FB7DF^ &tGH"&":":66"JGJ"oofVnlKO==@"477S=4#7:a#adj#jkk ..v7I?[M(6,>+PQ.;*+,,V^[QL'6NK+HI'+'>'>v|'T$!88Wf9UVVHDtww)XXYY, f--A 	"j [Z  WsG   OO	H=OO.OODOO2OOOOr1   c                   K   |t        | j                  dz         | j                          d{    | j                  |      }| j	                  |dd      }| j                  |ddg      }d}d}i }|||d<   n|d   r||d<   n||d<   |d   ry|d   |d<   |d	   r*| j                  | j                  ||             d{   }n.|d
   r)| j                  | j                  ||             d{   }| j                  |di       }nV|d   r9||d<   |d   |d<   | j                  | j                  ||             d{   }|}nt        | j                  dz         | j                  ||      S 7 A7 7 7 8w)a,  
        fetches information on an order made by the user

        https://www.bitrue.com/api_docs_includes_file/spot/index.html#query-order-user_data
        https://www.bitrue.com/api_docs_includes_file/futures/index.html#query-order-user_data-hmac-sha256

        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentorigClientOrderIdr  r  r@   r1   rT  r   r  rJ  r>   r  z, fetchOrder only support spot & swap markets)r   r1   rK  r  rB  r  fapiV2PrivateGetOrderrW  dapiV2PrivateGetOrderr&  spotV1PrivateGetOrderr$   r  	r  r1   r  r  r  r  r  rJ  r\  s	            r  fetch_orderzbitrue.fetch_order  s     >#DGG.X$XYY!!!V$ --f6I?[6$7#IJ$!#GIf~+<(/@+,&>&,TlGN#h!%!;!;DKKQW<X!YY	"!%!;!;DKKQW<X!YY>>(FB7DF^!#GI &tGH!77GV8TUUHDtww)WWXXX f--O 	"" ZY
 VsG   .E:E1BE:E4.E:0E61AE:?E8 2E:4E:6E:8E:c                 v  K   |t        | j                  dz         | j                          d{    | j                  |      }|d   st	        | j                  dz         d|d   i}|||d<   |||d<   | j                  | j                  ||             d{   }| j                  ||||      S 7 7 w)	aQ  
        fetches information on multiple closed orders made by the user

        https://www.bitrue.com/api_docs_includes_file/spot/index.html#all-orders-user_data

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz/ fetchClosedOrders() requires a symbol argumentr>   z, fetchClosedOrders only support spot marketsr  r1   	startTimer  )r   r1   rK  r  r$   spotV1PrivateGetAllOrdersrW  parse_orders)r  r  r  r  r  r  r\  r  s           r  fetch_closed_orderszbitrue.fetch_closed_ordersn  s      >#DGG._$_``!!!V$f~tww)WWXXfTl
 #(GK $GG77GV8TUU.   65%@@M 	" Vs"   .B9B5A+B9B7B97B9c                 r  K   |t        | j                  dz         | j                          d{    | j                  |      }d}d}i }|d   ry|d   |d<   |d   r*| j	                  | j                  ||             d{   }n.|d   r)| j                  | j                  ||             d{   }| j                  |dg       }nQ|d	   r4|d   |d
<   | j                  | j                  ||             d{   }|}nt        | j                  dz         | j                  ||||      S 7 7 7 7 9w)a  
        fetch all unfilled currently open orders

        https://www.bitrue.com/api_docs_includes_file/spot/index.html#current-open-orders-user_data
        https://www.bitrue.com/api_docs_includes_file/futures/index.html#cancel-all-open-orders-trade-hmac-sha256

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- fetchOpenOrders() requires a symbol argumentr@   r1   rT  r   r  rJ  r>   r  z1 fetchOpenOrders only support spot & swap markets)r   r1   rK  r  fapiV2PrivateGetOpenOrdersrW  dapiV2PrivateGetOpenOrdersr  spotV1PrivateGetOpenOrdersr$   r  	r  r  r  r  r  r  r  rJ  r\  s	            r  fetch_open_orderszbitrue.fetch_open_orders  sF     >#DGG.]$]^^!!!V$&>&,TlGN#h!%!@!@WV\A]!^^	"!%!@!@WV\A]!^^>>(FB7DF^ &tGH!<<T[[RX=YZZHDtww)\\]]^   vue<<A 	" _^ [sG   .D7D/AD7D1.D71D32A	D7;D5<4D71D73D75D7c                   K   |t        | j                  dz         | j                          d{    | j                  |      }| j	                  |dd      }| j                  |ddg      }d}d}i }|||d<   n|d   r||d<   n||d<   |d   ry|d   |d<   |d	   r*| j                  | j                  ||             d{   }n.|d
   r)| j                  | j                  ||             d{   }| j                  |di       }nQ|d   r4|d   |d<   | j                  | j                  ||             d{   }|}nt        | j                  dz         | j                  ||      S 7 <7 7 7 8w)aE  
        cancels an open order

        https://github.com/Bitrue-exchange/Spot-official-api-docs#cancel-order-trade
        https://www.bitrue.com/api-docs#cancel-order-trade-hmac-sha256
        https://www.bitrue.com/api_docs_includes_file/delivery.html#cancel-order-trade-hmac-sha256

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr  r  r  r@   r1   rT  r   r  rJ  r>   r  z- cancelOrder only support spot & swap markets)r   r1   rK  r  rB  r  fapiV2PrivatePostCancelrW  dapiV2PrivatePostCancelr&  spotV1PrivateDeleteOrderr$   r  r  s	            r  cancel_orderzbitrue.cancel_order  s     >#DGG.Y$YZZ!!!V$ --f6I?[6$7#IJ$!#GIf~+<(/@+,&>&,TlGN#h!%!=!=dkk'SY>Z![[	"!%!=!=dkk'SY>Z![[>>(FB7DF^ &tGH!::4;;wPV;WXXHDtww)XXYY* f--_ 	"" \[ YsG   .E5E,BE5E/.E50E11A	E5:E3;2E5/E51E53E5c                   K   | j                          d{    | j                  |      }d}d}|d   rxd|d   i}|d   r*| j                  | j                  ||             d{   }n.|d   r)| j	                  | j                  ||             d{   }| j                  |dg       }nt        | j                  dz         | j                  ||      S 7 7 s7 Fw)	ad  
        cancel all open orders in a market

        https://www.bitrue.com/api-docs#cancel-all-open-orders-trade-hmac-sha256
        https://www.bitrue.com/api_docs_includes_file/delivery.html#cancel-all-open-orders-trade-hmac-sha256

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :returns dict[]: a list of `order structures <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
        Nr@   rT  r1   r   r  rJ  z, cancelAllOrders only support future markets)	rK  r  fapiV2PrivatePostAllOpenOrdersrW  dapiV2PrivatePostAllOpenOrdersr  r$   r1   r  r  s          r  cancel_all_orderszbitrue.cancel_all_orders5	  s      !!!V$&>tG h!%!D!DT[[QXZ`Ea!bb	"!%!D!DT[[QXZ`Ea!bb>>(FB7Dtww)WWXX   v..1 	" cbs5   CCAC%C&.CCACCCc                   K   | j                          d{    |t        | j                  dz         | j                  |      }d}d}i }|||d<   ||dkD  rd}||d<   |d   ry|d   |d<   |d	   r*| j	                  | j                  ||             d{   }n.|d
   r)| j                  | j                  ||             d{   }| j                  |dg       }nQ|d   r4|d   |d<   | j                  | j                  ||             d{   }|}nt        | j                  dz         | j                  ||||      S 7 .7 7 7 :w)a  
        fetch all trades made by the user

        https://www.bitrue.com/api_docs_includes_file/spot/index.html#account-trade-list-user_data
        https://www.bitrue.com/api_docs_includes_file/futures/index.html#account-trade-list-user_data-hmac-sha256

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nz+ fetchMyTrades() requires a symbol argumentr  r7   r  r@   r1   rT  r   r  rJ  r>   r  z/ fetchMyTrades only support spot & swap markets)rK  r   r1   r  fapiV2PrivateGetMyTradesrW  dapiV2PrivateGetMyTradesr  spotV2PrivateGetMyTradesr$   r  r  s	            r  fetch_my_tradeszbitrue.fetch_my_trades[	  sr     !!!>#DGG.[$[\\V$#(GK t|$GG&>&,TlGN#h!%!>!>t{{7TZ?[!\\	"!%!>!>t{{7TZ?[!\\>>(FB7DF^ &tGH!::4;;wPV;WXXHDtww)ZZ[[\   vue<<O 	"  ]\ YsG   EEB EE.EE	A	EE4EE	EEr  c                 d  K   |t        | j                  dz         | j                          d{    | j                  |      }|d   dd}|||d<   |||d<   | j	                  | j                  ||             d{   }| j                  |dg       }| j                  ||||      S 7 {7 -w)	a*  
        fetch all deposits made to an account

        https://github.com/Bitrue-exchange/Spot-official-api-docs#deposit-history--withdraw_data

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz) fetchDeposits() requires a code argumentr1   r   r  r  r  r  rJ  )r   r1   rK  r  spotV1PrivateGetDepositHistoryrW  r  parse_transactions	r  r  r  r  r  r  r\  r  rJ  s	            r  fetch_depositszbitrue.fetch_deposits	  s      <#DGG.Y$YZZ!!!==&TN
 #(GK $GG<<T[[RX=YZZJ ~~h3&&tXueDDk 	" [s"   .B0B,AB0 B.,B0.B0c                 `  K   |t        | j                  dz         | j                          d{    | j                  |      }|d   dd}|||d<   |||d<   | j	                  | j                  ||             d{   }| j                  |dg       }| j                  ||      S 7 y7 +w)	a6  
        fetch all withdrawals made from an account

        https://github.com/Bitrue-exchange/Spot-official-api-docs#withdraw-history--withdraw_data

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz, fetchWithdrawals() requires a code argumentr1   r   r0  r  r  rJ  )r   r1   rK  r  spotV1PrivateGetWithdrawHistoryrW  r  r2  r3  s	            r  fetch_withdrawalszbitrue.fetch_withdrawals	  s      <#DGG.\$\]]!!!==&TN
 #(GK $GG==dkk'SY>Z[[0 ~~h3&&tX66Q 	" \s"   .B.B*AB. B,*B.,B.c                 f    dddddddd}| j                  ||i       }| j                  |||      S )Npendingr  )r   r  r  )r   56)r  
withdrawal)r&  r  )r  r  r  statusesByTyper  s        r   parse_transaction_status_by_typez'bitrue.parse_transaction_status_by_type.
  sO     
 
 
 >>.$;&&99r  transactionr  c                    | j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }d }d }|n|5|j                  d      }	| j                  |	d      }| j                  |	d      }|5|j                  d      }	| j                  |	d      }| j                  |	d      }| j                  |d	      }
| j                  |d
      }| j                  |d      }d|v }d|v }|s|rdnd}| j	                  | j                  |d      |      }| j                  |d      }d }| j                  |dd      }|G|j                  d      }	| j                  |	d      }| j                  |	d      }||j                         }| j                  ||      }| j                  |d      }d }|||d}i d|d|d	|
d|d| j                  |      d|d|d|d|d|d|d|d|d|d|d|d |d!d |d"S )#Nr1   
withdrawIdtagType	addressToaddressFrom_r   r   txid	createdAt	updatedAt	payAmountr  r<  r  r  r  r  r  r  )r  r   r  r@  rA  r  addresstagtagTotagFromr  r  r  F)internalcommentr  )	rC  r  r$  r  r>  r  r  r  rD  )r  r?  r  r1   rB  rC  rD  rL  rM  partsrF  r@  r  rI  r  r  r  r  r  rG  r  r  feeCostr  s                           r  parse_transactionzbitrue.parse_transaction=
  s   z T<@"";	:$$[+>	&&{MB$!, ,,UA6	((2&#))#."..ua8**5!4V4%%k;?	##K= K/	K' )U|66t7G7GU]7^`de!!+x8''XvF
!$$S)E))%3J((2I$#//+&&z8<"";6#W5C
K
"
 D
 	

 Y/
 w
 y
 
 ;
 5
 U
 w
 D
 f
 
  f!
" w#
$ )
 	
r  rJ  c                   K   | j                  ||      \  }}| j                  |       | j                          d{    | j                  |      }|d   ||d}d}| j	                  |      \  }}|| j                  |      |d<   |||d<   | j                  | j                  ||             d{   }	| j                  |	di       }
| j                  |
|      S 7 7 +w)a  
        make a withdrawal

        https://github.com/Bitrue-exchange/Spot-official-api-docs#withdraw-commit--withdraw_data

        :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 exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr1   )r  r  rC  	chainNamerK  rJ  )
handle_withdraw_tag_and_paramscheck_addressrK  r  handle_network_code_and_paramsnetwork_code_to_idspotV1PrivatePostWithdrawCommitrW  r&  rR  )r  r  r  rJ  rK  r  r  r\  networkCoder  rJ  s              r  r   zbitrue.withdraw
  s      99#vFV7#!!!==&TN 
 "AA&IV"#'#:#:;#GGK ? GEN==dkk'SY>Z[[  ~~h3%%dH55E 	"" \s"   :C CA5C 2C3*C C c                    | j                  |dg       }t        |      }|d d dd d di d}|dk7  rt        d|      D ]  }||   }| j                  |d      }| j                  |d      }	| j	                  ||	      }
d d d| j                  |d      ddd	|d
   |
<   |dk(  se| j                  |d      |d   d<   d|d   d<    |S )Nr  )r  r   )r  r   r  rw  r   r  r  r  F)r  r   rw  r   r   r  r   )r  r  r  r  r  r  )r  r  r  chainDetailschainDetailLengthr  r  r  r  currencyCoderZ  s              r  parse_deposit_withdraw_feez!bitrue.parse_deposit_withdraw_fee
  s    ~~c="=-"
 " 
 !1/0 =*1o ,,['B	#//&A"55iN'+4@(,(8(8m(Tdi j3z";/ %)040@0@m0\F:&u-7<F:&|4= r  codesc                    K   | j                          d{    | j                  |       d{   }| j                  |d      }| j                  ||d      S 7 B7 +w)a~  
        fetch deposit and withdraw fees

        https://github.com/Bitrue-exchange/Spot-official-api-docs#exchangeInfo_endpoint

        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        Nr  r  )rK  r  r  parse_deposit_withdraw_fees)r  r`  r  r  r  s        r  fetch_deposit_withdraw_feesz"bitrue.fetch_deposit_withdraw_fees  s[      !!!99&AAx1//ufEE 	"As   AAAA*AAc           
      6   | j                  |d      }d }d }|5|j                  d      }| j                  |d      }| j                  |d      }| j                  |d      }|d || j                  |      | j                  |d      | j	                  |d      ||dd		S )
NtransferType_to_r   r   r  r  r  r  )	r  r1   r@  rA  r  r  fromAccount	toAccountr  )r  r$  r  rD  r  )r  r   r  re  rg  rh  accountSplitr@  s           r  parse_transferzbitrue.parse_transfer  s      ''.A	#'--f5L**<;K((q9I%%h8	"Y/((6:&&x:&"

 
	
r  c                   K   | j                          d{    | j                  |dd      }d|i}d}|| j                  |      }|d   |d<   |||d<   ||dkD  rd}||d<   | j                  |d	      }|| j	                  |d	      }||d
<   | j                  | j                  ||             d{   }	| j                  |	dg       }
| j                  |
|||      S 7 7 -w)a  
        fetch a history of internal transfers made on an account

        https://www.bitrue.com/api-docs#get-future-account-transfer-history-list-user_data-hmac-sha256
        https://www.bitrue.com/api_docs_includes_file/delivery.html#get-future-account-transfer-history-list-user_data-hmac-sha256

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch transfers for
        :param str [params.type]: transfer type wallet_to_contract or contract_to_wallet
        :returns dict[]: a list of `transfer structures <https://github.com/ccxt/ccxt/wiki/Manual#transfer-structure>`
        Nr  re  r1   
coinSymbol	beginTime   r  r  endTimerJ  )	rK  rC  r  r  r  &fapiV2PrivateGetFuturesTransferHistoryrW  r  parse_transfers)r  r  r  r  r  r  r\  r  r  r  rJ  s              r  fetch_transferszbitrue.fetch_transfersA  s     !!!!!&&.AD
 }}T*H$,TNGL!#(GK s{$GG!!&'2YYvw/F!&GIDDT[[QXZ`Eabb ~~h3##D(E5AAE 	"& cs"   C#CBC#3C!4,C#!C#rg  rh  c                   K   | j                          d{    | j                  |      }| j                  | j                  di       }| j	                  |||      }| j	                  |||      }	|d   | j                  ||      |dz   |	z   d}
| j                  | j                  |
|             d{   }| j                  |di       }| j                  ||      S 7 7 +w)a  
        transfer currency internally between wallets on the same account

        https://www.bitrue.com/api-docs#new-future-account-transfer-user_data-hmac-sha256
        https://www.bitrue.com/api_docs_includes_file/delivery.html#user-commission-rate-user_data-hmac-sha256

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://github.com/ccxt/ccxt/wiki/Manual#transfer-structure>`
        Nry  r1   rf  )rl  r  re  rJ  )	rK  r  r&  r   r  currency_to_precision fapiV2PrivatePostFuturesTransferrW  rj  )r  r  r  rg  rh  r  r  accountTypesfromIdtoIdr\  r  rJ  s                r  r   zbitrue.transfert  s      !!!==&~~dll4DbI!!,[IiC"4.00v>"VOd2

 >>t{{7TZ?[\\ ~~h3""422' 	" ]s"   C CBC 2C3*C C r  c                   K   |t        | j                  dz         |dk  s|dkD  rt        | j                  dz         | j                          d{    | j	                  |      }d}|d   |d}|d   st        | j                  d	z         |d
   r+| j                  | j                  ||             d{   }|S |d   r)| j                  | j                  ||             d{   }|S 7 7 87 
w)a  
        set the level of leverage for a market

        https://www.bitrue.com/api-docs#change-initial-leverage-trade-hmac-sha256
        https://www.bitrue.com/api_docs_includes_file/delivery.html#change-initial-leverage-trade-hmac-sha256

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr   }   z% leverage should be between 1 and 125r1   )rT  r  r@   z& setLeverage only support swap marketsr   r  )	r   r1   r   rK  r  r$   fapiV2PrivatePostLevelEditrW  dapiV2PrivatePostLevelEdit)r  r  r  r  r  r  r\  s          r  set_leveragezbitrue.set_leverage  s     >#DGG.Y$YZZqLhnTWW'NNOO!!!V$"4L 
 f~tww)QQRR(!<<T[[RX=YZZH  I!<<T[[RX=YZZH 	" [Zs7   AC5C/A%C58C19/C5(C3)C51C53C5c                 "    ||d   d dd d d d d d d
S )Nr  isolated)
r  r  r  r  r  totalr  r  r@  rA   )r  rJ  r  s      r  parse_margin_modificationz bitrue.parse_margin_modification  s1     X&$
 	
r  c                   K   | j                          d{    | j                  |      }|d   st        | j                  dz         d}|d   | j	                  |      d}|d   r*| j                  | j                  ||             d{   }n.|d   r)| j                  | j                  ||             d{   }| j                  ||      S 7 7 G7 w)a  
        Either adds or reduces margin in an isolated position in order to set the margin to a specific value

        https://www.bitrue.com/api-docs#modify-isolated-position-margin-trade-hmac-sha256
        https://www.bitrue.com/api_docs_includes_file/delivery.html#modify-isolated-position-margin-trade-hmac-sha256

        :param str symbol: unified market symbol of the market to set margin in
        :param float amount: the amount to set the margin to
        :param dict [params]: parameters specific to the exchange API endpoint
        :returns dict: A `margin structure <https://github.com/ccxt/ccxt/wiki/Manual#add-margin-structure>`
        Nr@   z$ setMargin only support swap marketsr1   )rT  r  r   r  )	rK  r  r$   r1   r  fapiV2PrivatePostPositionMarginrW  dapiV2PrivatePostPositionMarginr  )r  r  r  r  r  r  r\  s          r  
set_marginzbitrue.set_margin  s      !!!V$f~tww)OOPP"4L++F3
 (!AA$++gW]B^__HI!AA$++gW]B^__H --h??) 	" `_s4   CCA4CC.C:C;CCCr   GETc                    | j                  |d      }| j                  |d      }| j                  |d      }	d }
|dk(  r|dk(  s|dk(  r'|j                  d      dk\  r| j                  d   |   }
n| j                  d   |   dz   |z   }
|
dz   | j                  ||      z   }
| j	                  || j                  |            }|	d	k(  r`| j                          | j                  | j                  d
d      }|dk(  s|dk(  r| j                  | j                  | j                         |d|            }| j                  | j                  |      | j                  | j                        t        j                         }|d|z   z  }d| j"                  i}|dk(  s|dk(  r
|
d|z   z  }
n|}d|d<   nt%        | j                               }d }|dk(  rd}n|dk(  rd}|dz   |z   dz   |z   }||z   |z   }|dk(  rt'        |j)                               }t+        |      }|dkD  r|d| j                  |      z   z  }| j                  | j                  |      | j                  | j                        t        j                         }| j"                  ||d}|
d| j                  |      z   z  }
n| j                  d
|i|      }| j-                  |      }||z  }| j                  | j                  |      | j                  | j                        t        j                         }d| j"                  ||d}n|r|
d| j                  |      z   z  }
|
|||dS )Nr   r   r   r   r   ru  	listenKeyr  r   rr  r  r>   )r@  rr  z&signature=zX-MBX-APIKEYr  DELETE?z!application/x-www-form-urlencodedContent-Typer   z/fapir   z/dapi)X-CH-APIKEY	X-CH-SIGNX-CH-TSzapplication/json)r  r  r  r  )r  methodbodyheaders)r  findr   implode_paramsr  extract_paramscheck_required_credentialsr  r   	urlencoderW  r  hmacencodesecrethashlibsha256apiKeystrr  r  r  json)r  pathr   r  r  r  r  r  r9   accessr  rr  query	signaturer@  signPathsignMessager  r  s                      r  signzbitrue.sign  sL   Q'""3*!!#q)EMg0dfnS^I_cdId))E"4(C))E"4(3.8CCi$--dF;;64#6#6t#<=Y++-**4<<tLJv~t{{!%",4 (  !IIdkk%&8$++dkk:RT[TbTbc	+i77"DKK eO8);3;&C D.QGN+

-	6>&HV^&H#c>G3c9D@'&08;U?.D!$TJ!A~#sT^^F-C'CC $		$++k*BDKKPTP[P[D\^e^l^l mI'+{{%.#,G
 3!777C KK$j)E  99U+D4'K $		$++k*BDKKPTP[P[D\^e^l^l mI(:'+{{%.#,	G sT^^F333fdwOOr  reasonr  r  r  r  c
                    |dk(  s|dk(  r0t        | j                  dz   t        |      z   dz   |z   dz   |z         |dk\  r|j                  d      dk\  rt	        | j                  dz   |z         |j                  d      dk\  rt	        | j                  d	z   |z         |j                  d
      dk\  rt	        | j                  dz   |z         |y | j                  |dd      }
|
s0| j                  |d      }d }|	 t        j                  |      }||}| j                  |d      }|`| j                  | j                  d   || j                  dz   |z          | j                  | j                  d   || j                  dz   |z          | j                  |d      }||dk(  st        j                  |d      ry |dk(  r*| j                  d   rt        | j                  dz   |z         | j                  dz   |z   }| j                  | j                  d   ||       t!        |      |
st!        | j                  dz   |z         y # t        $ r}d }Y d }~Cd }~ww xY w)Ni  i  r  i  zPrice * QTY is zero or lessr   z- order cost = amount * price is zero or less r  z5 order amount should be evenly divisible by lot size r  z order price is invalid, i.e. exceeds allowed price precision, exceeds min price or max price limits or is invalid float value in general, use self.price_to_precision(symbol, amount) successTmsgr  r  r  200r   r  rp  z temporary banned: )r%   r1   r  r  r!   r  r  r  loads	Exceptionthrow_exactly_matched_exceptionr  throw_broadly_matched_exceptionr,   string_equalsr   r   )r  r  r  r  r  r  r  r  requestHeadersrequestBodyr  messageInnerparsedMessageemessageerrorfeedbacks                    r  handle_errorszbitrue.handle_errors3  s   CKTS[ 3T!:S!@6!IC!ORV!VWW 3;yy671<"477-\#\_c#cddyy$)"477-d#dgk#kllyy(A-"477  .g  $g  jn  $n  o  o ..9d;++He<L M')$(JJ|$<M !,,H""8U3001I7TXT[T[^aTadkTkl001I7TXT[T[^aTadkTkl  62 7#8#8#D  dll3X&Y$TWW/D%Dt%KLLww}t+H001I5RZ[))# 4555 ! )$(M)s   <I 	IIIc                     d|v r	d|vr|d   S d|v r<d|v r8|d   }|d   }t        dt        |            D ]  }||   }	||	d   k  s|	d   c S  | j                  |dd      S )Nr   r  r   r  r   r   r   )r  r  r  )
r  r   r  r  r  configr  r   r  r  s
             r  calculate_rate_limiter_costz"bitrue.calculate_rate_limiter_costg  s    & 8v+=*%%6!6(97OEY'G1c'l+ $
E!H$ 8O$ vvq11r  )N)I__name__
__module____qualname__r   r  r  r  r	   r  r   r  r   r   r  dictr5  r   rH  rR  r  r   r^  r   r  r  r  r  r  r   r  r   r  r   r  r  r   r  r   r  floatr  r   r   r   r  r  r  r   r%  r)  r.  r   r4  r7  r>  r   rR  r   r_  rc  rj  r   rr  r   r}  r
   r  r  r  intr  r  __classcell__)r  s   @r  r.   r.   #   sS   A
# A
FD )+ 
4 ') 9S 9" -/ f: fP *, `+V `+Da
4 a
F a
F>) >)@ *, k* k*Z @DB CS C CS\ CJA4 A A6 AF 68 G/ G/F G/R 8<$]ajl SH SHC SHWZ SHquvzq{ SHj#
 #
4 #
J 8<B :1W :1x 6:" P47 P4 P4dW Wv W Wr <@d[] 'A 'AS 'A 'Abfglbm 'AR: :n nv n n` XZ Tc T T& mqy{ y. y.I y.Y y.X] y.fi y.v 8<B U.C U. U.n 7;\`ik 4A 4A3 4AVY 4Aptuzp{ 4Al 59tZ^gi O=c O= O=TW O=nrsxny O=b 9=R >.S >.# >.@ 59 $/c $/L 37TX\eg T=C T=s T=RU T=l 04$UYbd CE CEC CEs CEimnyiz CEJ 37TX\eg 67C 67s 67RU 67lpq|l} 67p:v
T v
X v
Q\ v
p JNVX 163 16 16 16]h 16f$ $L BFb Fw F"
H 154VZce 1B# 1BS 1BPS 1Bjno|j} 1Bf ac !33 !3 !3C !3TW !3gt !3F ?C2 3  >
>P 
. CE  @s  @E  @I[  @D &eBSW BPH2# 2s 2 2c 2TX 2`c 2h MO 
2r  r.   )5 ccxt.async_support.base.exchanger   ccxt.abstract.bitruer   r  r  r  ccxt.base.typesr   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%   r&   r'   r(   r)   ccxt.base.decimal_to_precisionr*   r+   ccxt.base.preciser,   r.   r  r  r  <module>r     s    6 ,    P  P  P  P  P  P  * 0 - - . ' & . ) * 5 ) + . 1 * ) 3 4 %N12X{ N12r  