
    !:h                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ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%m0Z0 d dl%m1Z1 d dl%m2Z2 d dl%m3Z3 d dl%m4Z4 d dl%m5Z5 d dl%m6Z6 d dl7m8Z8 d dl7m9Z9 d dl:m;Z;  G d dee      Z<y)    )Exchange)ImplicitAPIN)AnyBalancesBorrowInterest
CurrenciesCurrencyDepositAddressFundingHistoryIntIsolatedBorrowRateIsolatedBorrowRatesLedgerEntryMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTransactionMarketInterfaceTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)NetworkError)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)TRUNCATE)	TICK_SIZE)Precisec                   :    e Zd Zdef fdZi fdefdZi fdZi fdee	   fdZ
i fdee	   fdZi fdee   fdZi fdefdZd	ed
edefdZi fdefdZddefdZi fdefdZddededefdZi fdedefdZdi fdedefdZdi fdededefdZddedede fdZ!ddi fdedededee    fdZ"dd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fd"Z&dddi fd#edededefd$Z'de(fd%Z)d& Z*i fde(fd'Z+dd(edede,fd)Z-i fdede,fd*Z.dd+edede/fd,Z0d- Z1d. Z2i fded/e3fd0Z4di fded1e5d2e6d3e3d4e7f
d5Z8i fd6ee9   fd7Z:di fded1e5d2e6d3e3d4e7f
d8Z;di fded1e5d2e6d3e3d4e7f
d9Z<di fd#edefd:Z=di fd;ee   dedee/   fd<Z>di fdefd=Z?dddi fdededefd>Z@dddi fdedededee/   fd?ZAdddi fdedededee/   fd@ZBdddi fdededefdAZCdi fd#edefdBZDi fdedeEfdCZFddeEfdDZGdi fded3e3dEedeHfdFZIdddi fdededefdGZJdi fd#edefdHZKdddi fdedededeeH   fdIZLdi fd#edefdJZMdddi fdedededeeH   fdKZNdLefdMZOddNededeHfdOZPi fdedefdPZQi fdeded3e3fdQZRddefdRZSi fdedeTfdSZUddTededeTfdUZVi fdeWfdVZXi fded3e3dWedXedeYf
dYZZdLedefdZZ[d[ Z\d\ Z]dd]ededeYfd^Z^dddi fdedededeeY   fd_Z_ddddi fdededededee`   f
d`ZaddTedede`fdaZbi fdefdbZcddefdcZddi fddedefdeZei fdedeffdfZgdddi fdededefdgZhddedeffdhZii fdefdiZjdi fdedeek   fdjZlddkedefdlZmdddi fdededefdmZnddefdnZoddi fd#eded1e5d2e6d3e7d4e7de/fdoZpdddi fdedededeeq   fdpZrddqededeqfdrZsds Ztddddi fdtedededefduZudddi fdedededeev   fdvZwddefdwZxddededeev   fdxZyddi fdefdyZzdi fdze{defd{Z|di fdefd|Z}d} Z~d~di ddfdZdedededededefdZ xZS )bitmartreturnc                    | j                  t        t        |          i dddddg 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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dedfdgdhdidjdkdldmdndodpdqdrdsddddtdudvi dwdxdydxdzd{d|d{d}d~dddddd~dddddddd~dddd~dddddd~d~dd~d~dddddd~d
ii dd{dd{dd~dd{dd~dd{dd{dd~dddd~dddddd{dd{dddddd~i dd~dddd~dddddddddd~dddddddd~ddddddddddddddddddi dddddddddddd{dd{dd{dd{dddddddddddddd~dd~i dd~dd~ddxdd͓ddxddddddddӓddddddddؓddؓddۓddӓddddddddddddddޜdߜddddxd~ddddddddddd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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t
        d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        d0t        d1t        d2t        d3t        d4t        d5t        d6t         d7t        d8t        d9t        d:t        i d;t"        d<t$        d=t        d>t        d?t        d@t        dAt        dt        dBt"        dCt        dDt        dEt        dFt&        dGt(        dHt(        dIt(        dJt(        i dKt(        dLt(        dMt(        dNt(        dOt        dPt        dQt        dRt        dSt        dTt        dUt        dVt        dWt        dXt"        dYt        dZt        d[t        i d\t        d]t        d^t(        d_t&        d`t&        dat&        dbt(        dct(        ddt(        det        dft        dgt        dht        dit"        djt        dkt        dlt"        i dmt        dnt        dot        dpt        dqt(        drt(        dst        dtt        dut(        dvt(        dwt(        dxt(        dyt(        dzt(        d{t(        d|t        d}t        i d~t        dt        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        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(        dt(        t(        t(        t(        t        t        t(        t(        t(        dt        t        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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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/d0d1d2d3d4d5d6d7d8d9d:d;d<dѐdѐdՐdАd=dd>didddkdd?d@
dddd dddd dddddAddddddddBdCdiddDd dEddFdddddGddDddddHd ddDd d d ddddIdJdKidL	dMddddddNdddddddNddOdddddAdddddPdd d dEdQddddRddSdddTddDd d d dddUdJdVidWdXdMidXdYidXdYidZd d dZd[d\      S (]  Nidr8   nameBitMart	countries)USCNHKKR	rateLimitgQ@@versionv2	certifiedTprohasCORSspotmarginswapfutureFoptionborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTrailingPercentOrderfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLiquidationsfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransferfetchTransfersfetchWithdrawAddressesfetchWithdrawAddressesByNetworkfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModesetPositionModetransferwithdrawhostnamezbitmart.comurlszOhttps://github.com/user-attachments/assets/0623e9c4-f50e-48c9-82bd-65c3908c3a14zhttps://api-cloud.{hostname}zhttps://api-cloud-v2.{hostname}rJ   rL   zhttps://www.bitmart.com/z"https://developer-pro.bitmart.com/z http://www.bitmart.com/?r=rQCFLhg333333?)urldiscountzhttps://www.bitmart.com/fee/en)logoapiwwwdocreferralfeesrequiredCredentials)apiKeysecretuidr   getzsystem/time   zsystem/servicezspot/v1/currenciesg      @zspot/v1/symbolszspot/v1/symbols/details   zspot/quotation/v3/tickers   zspot/quotation/v3/ticker   zspot/quotation/v3/lite-klineszspot/quotation/v3/klines   zspot/quotation/v3/bookszspot/quotation/v3/tradeszspot/v1/tickerzspot/v2/ticker   zspot/v1/ticker_detailzspot/v1/stepszspot/v1/symbols/klinezspot/v1/symbols/book   )
zspot/v1/symbols/tradeszcontract/v1/tickerszcontract/public/detailszcontract/public/depthzcontract/public/open-interestzcontract/public/funding-ratez$contract/public/funding-rate-historyzcontract/public/klineaccount/v1/currencieszcontract/public/markprice-klinez$account/sub-account/v1/transfer-listz'account/sub-account/v1/transfer-historyz"account/sub-account/main/v1/walletz+account/sub-account/main/v1/subaccount-listz+account/contract/sub-account/main/v1/walletz2account/contract/sub-account/main/v1/transfer-listz0account/contract/sub-account/v1/transfer-historyzaccount/v1/walletr   zspot/v1/walletzaccount/v1/deposit/addresszaccount/v1/withdraw/charge    z#account/v2/deposit-withdraw/historyz"account/v1/deposit-withdraw/detailz account/v1/withdraw/address/listzspot/v1/order_detail   zspot/v2/orderszspot/v1/tradeszspot/v2/tradeszspot/v3/orderszspot/v2/order_detailz%spot/v1/margin/isolated/borrow_recordz$spot/v1/margin/isolated/repay_recordzspot/v1/margin/isolated/pairszspot/v1/margin/isolated/accountzspot/v1/trade_feezspot/v1/user_feezspot/v1/broker/rebatezcontract/private/assets-detailzcontract/private/orderg333333?zcontract/private/order-history
   zcontract/private/positionzcontract/private/position-v2z contract/private/get-open-orders)z#contract/private/current-plan-orderzcontract/private/tradeszcontract/private/position-riskz%contract/private/affilate/rebate-listz$contract/private/affilate/trade-listz$contract/private/transaction-historyz"contract/private/get-position-modez'account/sub-account/main/v1/sub-to-mainz&account/sub-account/sub/v1/sub-to-mainz'account/sub-account/main/v1/main-to-subz%account/sub-account/sub/v1/sub-to-subz&account/sub-account/main/v1/sub-to-subz0account/contract/sub-account/main/v1/sub-to-mainz0account/contract/sub-account/main/v1/main-to-subz/account/contract/sub-account/sub/v1/sub-to-mainzaccount/v1/withdraw/applyzspot/v1/submit_orderzspot/v1/batch_orderszspot/v2/cancel_orderzspot/v1/cancel_orderszspot/v4/query/orderzspot/v4/query/client-orderzspot/v4/query/open-orderszspot/v4/query/history-orderszspot/v4/query/tradeszspot/v4/query/order-tradeszspot/v4/cancel_orderszspot/v4/cancel_allZ   zspot/v4/batch_orderszspot/v3/cancel_orderzspot/v2/batch_orderszspot/v2/submit_orderzspot/v1/margin/submit_orderg      ?zspot/v1/margin/isolated/borrowzspot/v1/margin/isolated/repayz spot/v1/margin/isolated/transferz!account/v1/transfer-contract-list<   zaccount/v1/transfer-contractzcontract/private/submit-orderg      @zcontract/private/cancel-orderzcontract/private/cancel-orders)z"contract/private/submit-plan-orderz"contract/private/cancel-plan-orderz contract/private/submit-leveragez#contract/private/submit-tp-sl-orderz"contract/private/modify-plan-orderz)contract/private/modify-preset-plan-orderz#contract/private/modify-limit-orderz#contract/private/modify-tp-sl-orderz#contract/private/submit-trail-orderz#contract/private/cancel-trail-orderz"contract/private/set-position-mode)r   post)publicprivate
timeframes-   x         i  i`'  i  )1m3m5m15m30m45m1h2h3h4h1d1w1Mr   tradingz0.0040z0.00350z0.002010z0.1850z0.0016250z0.00141000z0.00125000z0.001025000z0.000850000z0.0006z0.001z0.0009z0.0007z0.0005z0.0004z0.0003)takermaker)	tierBased
percentager   r   tiersprecisionMode
exceptions300003000130002300033000430005300063000730008300103001130012300133001430016300173001830019600006000160002600036000460005600066000760008600096001060011600126002060021600226002660027600286002960030600316005060051610016100361004610056100661007610087000070001700027000371001710027100371004710055000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425100051001510025100351004510055100651007510085100951010510115101251013510145101552000520015200252003520045300053001530025300353005530065300753008530095301057001580015900159002590035900459005590065900759008590095901059011400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042)4004340044400454004640047400484004940050)z1You contract account available balance not enoughz1you contract account available balance not enough)exactbroadcommonCurrencies	GOLDMINERz	Step HeroPACBEYONDzGorilla DiamondGoldariozMVP CoinTruebit)z$GMz$HEROz$PACBPGDTGLDMVPTRUTRC20BTCERC20)USDTr  ETHr   SOLOMNIXLMEOSNEOBTMBCHLTCBSVXRPPLEXXCHNEARFIOSCRTIOTXALGOATOMDOTADADOGEXYMGLMRMOVRZILINJKSMZECNASPOLYGONMATICHRC20HECOXDCONELATCSPRCasperICPComputerXTZMINABEP20BSC_BNBTHETAAKTARCELOFILNULSETCDASHDGBBEP2GRINWAVESABBCACAQTUMTLOSKARDIAKardiaChainFUSETRC10FIROFTMFantomEVERKAVAHYDRAPLCUBRISEOPTIMISMREEFSYSVITESTXSXPBITCIXRDASTRASTARZENHORIZENLTOETHWETHFIOSTAPTONTEVMOSXMROASOSMOz
OMAX ChainDESOBFICOHOCSCHEQNODLXEMFRAERG)r  r  OASYSr  OMAXr  r  r  r  r  r  NEMr  ERGO)r  Ethereumr  BitcointypeCCXTxBitmart000)
defaultNetworkstimeDifferenceadjustForTimeDifferencenetworksnetworksByIddefaultTyper_   accountsByType!createMarketBuyOrderRequiresPricebrokerId)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingmarketBuyRequiresPricemarketBuyByCostleverageselfTradePreventionicebergmax   i )r0  limitdaysBack	untilDayssymbolRequired)r0  triggerr9  rD  )r0  rA  rE  r9  rD  )r0  rA  rB  daysBackCanceledrC  rE  r9  rD  rA    )	sandboxrW   rX   r{   r   r   r   rd   r|   default)lastmarkindex)r2  price)r0  r1  r2  r3  r4  r5  r6  r7  r8  r9  r:  r;  )r0  rA  rB  rC  )r0  rE  r9  d   )r0  rA  rE  r9  )r0  rA  rB  rF  rC  rE  r9    )extendsrW   r{   r   r   rd   r|   rP  forDerivatives)linearinverse)rI  rQ  rJ   rL   rM   )optionsfeatures)deep_extendsuperr8   describeparse_numberr5   r#   r$   r&   r%   r0   r1   r2   r(   r+   r*   r.   r)   r/   r-   r,   r3   )self	__class__s    F/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/bitmart.pyrX  zbitmart.describe#   s   gt = ? LB
)LB
ILB
 1LB
 LB
 tLB
 LB
 4LB
  VVV $V 	V
 %V %V $UV 'V "4V tV V /V ,UV 0V tV  !V" &t#V$ (%V& ''V( ()V* "5+V, -d-V. /V0 &t1V2 +E3V4 )%5V6 &t7V8 $T9V: ';V< (=V> "4?V@ AVB &tCVD (EVF 1%GVH  IVJ *4KVL +EMVN &tOVP #DQVR *5SVT $UUVV *4WVX +DYVZ t[V\ $U]V^ "5_V` aVb !$cVd &teVf  gVh diVj $TkVl +EmVn "4oVp dqVr !$sVt uuVv #DwVx  yVz $T{V| !$}V~ tV@ tAVB CVD TEVF tGVH "4IVJ #EKVL &tMVN 'OVP  QVR !$SVT )$UVV 25WVX "4YVZ #D[V\ ]V^ #E_V` &taVb tcVd  eVf "4gVh DiVj DkVLB
B CLB
D i:= 2;= # 9ELB
` "$aLB
j  %q(! -c	
 *3 21 4Q 3A 8 3A 21 3A )! )" 0  (!" 0#$ /%& 34/134129;8:@B1213;<; D1>1 B31 =a	1
 Fs1 Fq1 Mc1 KC1 ,Q1 01 )!1 5b1 5b1 >s1  =c!1" ;B#1& /'1( )!)1* )!+1. )!/10 )!112 /316 @718 ?91: 8;1< :1=1> ,R?1@ +BA1D 0E1H 9!I1J 1#K1L 9"M1N 4RO1P 7Q1R ;CS1T @C35:<AC@B@B>?a1d4A24 A"4 B2	4
 @4 A"4 KC4 KC4 J34 4S4 /4 /4 /4  0!4" .q#4$ 5a%4& 4Q'4( 7)4* /+4, 5a-4. 0/40 -b142 /346 /748 /94: /;4> 6s?4@ 9"A4B 8C4D ;BE4H <RI4J 7K4L 8M4N 8O4P 9"Q4R ?B>A<??B>AEH?B?B?B?B>?g4ghEKkLB
B CLB
` !%"&!..x8!..x8 "..s3T5F5Fx5PQ!..t4d6G6G6OP!..t4d6G6G6QR!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..w79J9J89TU!..w79J9J89TU	" "..s3T5F5Fw5OP!..t4d6G6G6QR!..t4d6G6G6QR!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..w79J9J89TU!..w79J9J89TU	"aLB
\	 Y]	LB
^	 J]J 0J 0	J
 -J 0J 0J 0J 0J 0J -J 0J 0J .J 1J  ]!J" .#J$ Z%J& -'J* Z+J, Z-J. Z/J0 ]1J2 ]3J4 ]5J6 ]7J8 ^9J: .;J< ]=J> ]?J@ ^AJB ]CJD -EJF -GJH -IJJ -KJL -MJN -OJP -QJR ZSJT ZUJV ]WJX ]YJZ .[J\ Z]J^ Z_J` ZaJb \cJd ]eJf ]gJj ]kJl ZmJn YoJp \qJr ZsJt ZuJv ZwJx ZyJz Z{J~ ZJ@ YAJB ZCJD ZEJF ZGJH ]IJJ \KJL \MJN \OJP \QJR \SJT \UJV \WJX \YJZ Z[J\ Z]J^ Z_J` ZaJb ZcJd ]eJf .gJh ZiJj 1kJl YmJn ZoJp ZqJr ZsJt ZuJv ZwJx \yJz ]{J| ]}J~ ]J@ \AJD \EJF \GJH ]IJJ ZKJL ZMJN ZOJP YQJR ]SJT ZUJV YWJX ]YJZ ][J\ ]]J^ ._J` \aJb \cJd ZeJf ]gJh \iJj \kJl \mJn \oJp \qJr \sJt \uJv ZwJx ZyJz Z{J| Z}J~ ZJ@ -AJB -CJD -EJF -GJH -IJJ -KJL -MJN -OJP -QJR -SJT ZUJV ZWJX ]YJZ ][J\ ]]J^ ]_J` -aJb ]cJd ]eJf ]gJh ]iJj .kJl ]mJp ]qJr ]sJt ]uJv ]wJx ]yJz -{J| Z}J~ \J@ ZAJB ZCJD ZEJF ]GJH ]IJJ YKJL YMJN \OJP \QJR \SJT ]UJV \WJX ]YJZ ][J\ ]]J^ ]_J` ]aJb ]cJd .eJf -gJh \iJj \kJl \mJn \oJp \qJr YsJt ]uJv \wJx ]yJz Z{J| Z}J~ \J@ \AJB \CJD *))--)))SJX J[IZYP_	LB
@ "$(!! 	!ALB
X $ "$
 #$+0VWV5V 5V W	V FV 5V 5V 5V 5V 5V 5V 5V  5!V$ F%V& 5'V* F+V, 5-V. F/V0 F1V2 F3V4 F5V6 57V8 59V: F;V< 5=V> F?V@ FAVB 5CVD 5EVF 5GVH 5IVJ 5KVL wMVN VOVP 5QVR 5SVT 5UVV HWVX :YVZ 5[V\ F]V^ Y_V` WaVb 5cVd $eVf FgVh 5iVj FkVl 5mVn FoVp 5qVr FsVt FuVv WwVx FyVz 5{V| F}V~ 5VF FGVH mIVJ FKVL WMVN FOVP 8QVV FWVX FYVZ W[V\ F]V^ W_Vd 
eVf FgVh 5iVj FkVl 5mVn 5oVp WqVt 5uVv GwVx 9yVz 5{V| F}V~ FV@ FAVD 5EVH 5IVJ % ""("" ""  !eVp # '"$	!  &F! #"# 6:-]od  %&*(-,0,1).+06:#'#("&#(	( #($)27+/$(/4#()$. r% '+!$$(%**/& ',#($)*/	# '+!$#($)*/( $(&*!$$(,0%)#($)*/	*  #u=~  )&*(,$($(%*-
 -1)-+/ )-(,).1
 &+7 $(#'"&#(	( #($(26+/9"$H '+!%$(%*	& ',#($(# ',!$#'$)	( '+!$$(,0%)#($)*  #B#H y
 "#3 "#3 	 ##[QuLB
 L L	    c                 n    | j                  |      }| j                  |di       }| j                  |d      S )aW  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://developer-pro.bitmart.com/en/spot/#get-system-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        dataserver_time)publicGetSystemTime	safe_dictsafe_integer)rZ  paramsresponser_  s       r\  
fetch_timezbitmart.fetch_timer  s;     ++F3 ~~h3  }55r]  c                     | j                  | j                  di       }| j                  | j                  d      }| j                  |d|      }| j                  |d|      }| j                  |d      }| j	                  |      }| j                  |di       }| j                  |dg       }| j                  |d      }|dk(  rd}| j                  ||      }	d	}
d	}|	.| j                  |	d
      }|dk(  rd}
nd}
| j                  |	d      }|
d	|d	|dS )a^  
        the latest known information on the availability of the exchange API

        https://developer-pro.bitmart.com/en/spot/#get-system-service-status

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
        r   r(  r!  r_  serviceservice_typerL   contractNstatus   okmaintenanceend_time)rk  updatedetar   info)rb  rT  safe_stringomitpublicGetSystemService	safe_listindex_byrc  )rZ  rd  rT  r(  r!  re  r_  servicesservicesByTyperh  rk  rq  
statusCodes                r\  fetch_statuszbitmart.fetch_status  s*    ..}bA&&t||]C=566*..v64 ~~h3>>$	26x@6>D"">48**7H=JQ&''<
 	
r]  c                    | j                  |      }| j                  |di       }| j                  |dg       }g }| j                  d   }t	        dt        |            D ]  }||   }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }|d	z   |z   }| j                  |d
      }| j                  |d      }t        j                  ||      }| j                  |d      }|j                  | j                  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    || j                  | j                  | j                  |d!                  d"d d d#|| j                  |d$      d#d d d#| j                  |      d d#d%d |d&              |S )'Nr_  symbolsr   r   symbol	symbol_idbase_currencyquote_currency/min_buy_amountmin_sell_amountbase_min_sizer;   	numericIdbasequotesettlebaseIdquoteIdsettleIdr!  rJ   TrK   FrL   rM   rN   activerj  r   r   price_max_precisionamountrM  minr?  base_max_sizer<  r  rM  costrR  rS  contractSizeexpiryexpiryDatetimestrike
optionTyper   r   	precisionlimitscreatedrr  )publicGetSpotV1SymbolsDetailsrb  rv  r   rangelenrs  rc  safe_currency_coder6   
string_maxsafe_numberappendsafe_market_structurerY  parse_precision)rZ  rd  re  r_  r}  resultr   imarketr;   r  r  r  r  r  r~  
minBuyCostminSellCostminCostbaseMinSizes                       r\  fetch_spot_marketszbitmart.fetch_spot_markets  s   55f=6 ~~h3..y"5yy#q#g,' @	AQZF!!&(3B))&+>I%%fo>F&&v/?@G**62D++G4ECZ%'F))&2BCJ**63DEK(([AG**6?CKMM$44 36b36Y36 &36 	36
 36 $36 &36 736 D36 36 36 %36 36 %36 %36  $!36" E#36$  $"&"gg)!..t/C/CDDTDTU[]rDs/tu  $#!
  +#//H
  $#
  $009#$  e36 3 3@	B r]  c                 X   | j                  |      }| j                  |di       }| j                  |dg       }g }| j                  d   }t	        dt        |            D ]  }||   }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |
      }| j                  |      }d}| j                  |      }|d	z   |z   d
z   |z   }| j                  |d      }|dk(  }|dk(  }| j                  |d      }|s|dk(  rd }|j                  | j                  i d|	dd d|d|d|d|d|
d|d|d|rdndddddd|d|ddddd ddd| j                  |d!      || j                  |      d d |d"   |d#   | j                  |d$      | j                  |d%      d&| j                  |d'      | j                  |d(      d)| j                  |d*      | j                  |d+      d)d d d)d d d)d,| j                  |d-      |d.              |S )/Nr_  r}  r   r   r~  r  r  r  r  :product_typer   rl  expire_timestampr;   r  r  r  r  r  r  r  r!  rL   rM   rJ   FrK   rN   r  Trj  contract_sizer   r   vol_precisionprice_precisionr  min_leveragemax_leverager  
min_volume
max_volumer  open_timestampr  )publicGetContractPublicDetailsrb  rv  r   r  r  rs  r  rc  r  r  r  iso8601)rZ  rd  re  r_  r}  r  r   r  r  r;   r  r  r  r  r  r  r~  productTypeisSwap	isFuturesr  s                        r\  fetch_contract_marketszbitmart.fetch_contract_markets+  s   66v>P ~~h3..y"5yy#q#g,' C	AQZF!!&(3B%%fo>F&&v/?@G**62D++G4EH,,X6FCZ%'#-6F++FNCK!Q&F$)I&&v/ABF&A+MM$44 36b36T36 &36 	36
 36 &36 &36 736 H36 &h36 36 %36 36 )36 %36  $!36" D#36$   $ 0 0 I "&,,v"6"gg"..vG!--f6GH  $//G#//G!
  $//E#//E
  $#
  $#$  ,,V5EFe36 3 3!C	H r]  c                     | j                   d   r| j                          | j                  |      }| j                  |      }| j	                  ||      S )at  
        retrieves data on all markets for bitmart

        https://developer-pro.bitmart.com/en/spot/#get-trading-pair-details-v1
        https://developer-pro.bitmart.com/en/futuresv2/#get-contract-details

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r%  )rT  load_time_differencer  r  array_concat)rZ  rd  rJ   rj  s       r\  fetch_marketszbitmart.fetch_markets  sP     <<12%%'&&v...v6  x00r]  c                    | j                  |      }| j                  |di       }| j                  |dg       }i }t        dt	        |            D ]I  }||   }| j                  |d      }|}	| j                  |d      }
|j                  d      dk\  }|sG|j                  d      }| j                  |d      }	| j                  |d      }||j                         }
| j                  |	      }| j                  ||      }|!||	|d	| j                  |d
      d	d	d	i |rdndd
}| j                  |
      }| j                  |d      }| j                  |d      }||
||||xr || j                  |d      | j                  |d      d	dd	d	ddd|d   |<   |||<   L t        |j                               }t        dt	        |            D ]   }||   }||   }| j                  |      ||<   " |S )a  
        fetches all available currencies on an exchange

        https://developer-pro.bitmart.com/en/spot/#get-currency-list-v1

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r_  
currenciesr   currencynetworkNFT-r   Nr<   othercrypto)
rr  r;   coder  r<   depositr   r  r&  r!  withdraw_enableddeposit_enabledwithdraw_feewithdraw_minsizer  )r   r  )rr  r;   r  r   r  r  feer  r&  )publicGetAccountV1Currenciesrb  rv  r  r  rs  findsplitupperr  network_id_to_code	safe_boolr  listkeyssafe_currency_structure)rZ  rd  re  r_  r  r  r  r  fullId
currencyId	networkIdisNtfpartssecondcurrencyCodeentrynetworkCoder   r  r  keys                        r\  fetch_currencieszbitmart.fetch_currencies  sA    44V<2 ~~h3^^D,;
q#j/* 1	)A!!}H%%h
;FJ((9=I[['1,ES)!--eQ7
))%3% &I22:>LNN6<8E}$$(!% ,,Xv># $" "',G( 11)<K~~h0BCHnnX/@AG #$"".w''.A  $//:LM#!
  $# 	.E*k*& $)F< c1	)d FKKM"q#d)$ 	AAq'Cc{H66x@F3K	A r]  r  r  c                 &   || j                  |      }| j                  |      }|d   }d }| j                  |di       }i }|x| j                  ||      }|>t        |j	                               }	t        |	      }
|
dkD  r| j                  ||	d         }| j                  |di       }| j                  |d      }nR| j                  ||      }|&| j                  |di       }| j                  |d      }n|d| j                  ||      z   z  }||S |S )Nr;   r&  r   rr  r  r  )	default_network_coder  rb  r  r  r  
safe_valuers  network_code_to_id)rZ  r  r  r  r;   idFromNetworkr&  networkInfor  r  lengthprovidedOrDefaultNetworks               r\  %get_currency_id_from_code_and_networkz-bitmart.get_currency_id_from_code_and_network  s&   33LAK==.d^!>>(J;nnX|<GHMMO,TA:"oohQ@G..&"=K ,,[*EM'+~~h'L$'3"nn-EvrR $ 0 0j IcD33KNNN!.!:}CCr]  r  c                 $   | j                          | j                  |      }d}| j                  |      \  }}d| j                  |d   |      i}| j	                  | j                  ||            }|d   }i }| j                  |d      ||<   ||i dS )ah  
 @deprecated
        please use fetchDepositWithdrawFee instead
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the network code of the currency
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        Nr  r  r_  r  )rr  r   r  )load_marketsr  handle_network_code_and_paramsr  !privateGetAccountV1WithdrawChargeextendr  )	rZ  r  rd  r  r  requestre  r_  withdrawFeess	            r\  fetch_transaction_feezbitmart.fetch_transaction_fee(  s     	==&==fEBB8FCSU\]
 99$++gv:VW !--dNCT$
 	
r]  Nr  c                 <    || j                  |d      d dd d di dS )Nr  )r  r   )rr  r   r  r&  )r  )rZ  r  r  s      r\  parse_deposit_withdraw_feez"bitmart.parse_deposit_withdraw_feeO  s;     ''^<"
 " 
 	
r]  c                     | j                          d}| j                  |      \  }}d| j                  ||      i}| j                  | j	                  ||            }|d   }| j                  |      S )a  
        fetch the fee for deposits and withdrawals

        https://developer-pro.bitmart.com/en/spot/#withdraw-quota-keyed

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the network code of the currency
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        Nr  r_  )r  r  r  r  r  r  )rZ  r  rd  r  r  re  r_  s          r\  fetch_deposit_withdraw_feez"bitmart.fetch_deposit_withdraw_feee  s|     	==fEBB4Q
 99$++gv:VW ..t44r]  tickerr  c           	         | j                  |dg       }| j                  |dd      }| j                  |dd      }| j                  |dd      }| j                  |dd	      }| j                  |d
d      }| j                  |d      }	| j                  |dd      }
| j                  |dd      }| j                  |dd      }| j                  |dd      }| j                  |dd      }| j                  |dd      }| j                  |d      }| j	                  |g d      }| j                  |g d      }| j                  |d      }||}| j                  |d      }| j                  |d      }
| j                  |d      }| j                  |d       }| j                  |d!      }| j                  |d"      }| j                  |d#      }| j                  |d$      }| j                  |d%      }| j                  |d&      }	| j                  |d'      }| j                  |d(      }| j                  ||      }|d   }|| j                  |d)d*      }|t        j                  |	d+      }||| j                  |d,|      }n|}d }| j                  i d|d|d-| j                  |      d.|
d/|d0|d1|d2|d3|d4d d5|d6|d	|d7d d8d d9|d:|||| j                  |d      |d;|      S )<Nr  	avg_priceindex_pricer~  contract_symbol	timestampts
last_pricerJ  price_change_percent_24h
change_24hfluctuationhigh_24h
high_pricelow_24h	low_pricebest_bidbid_pxbest_bid_sizebid_szbest_askask_pxbest_ask_sizeask_szopen_24h)base_volume_24hv_24h
volume_24h)quote_volume_24hqv_24hturnover_24hr      r   r      	   r      r   r   r   rl  r   s_trG  100r  datetimehighlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechanger   average)
baseVolumequoteVolume
indexPricerr  )rv  safe_string_2safe_integer_2rs  safe_string_nsafe_string_lower_nrc  safe_string_lowersafe_marketsafe_integer_productr6   
string_mulsafe_tickerr  )rZ  r  r  r  r.  marketIdr  rJ  r   r-  r#  r$  r%  r&  r'  r(  r*  r/  r0  listMarketIdr~  s                        r\  parse_tickerzbitmart.parse_ticker  s   h "5$$V[-H%%fh8IJ''TB	!!&,?''0JLY
!!&-8!!&*lC  K@  X>&&vI	  X>&&vI	
3''0Z[
..v7ef''2##H))&"5I##FA.D""61-C""61-C((3I""62.C((4I##FA.D##FA.D%%fa0F))&!4J00;K!!(F3!11&%FI ++FE:J!"..v|[Q )!
 !
f!
!
 Y/!
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  *!!
" w#!
$ %&**6=A+!
, - 	r]  r~  c                    | j                          | j                  |      }i }d}|d   r*|d   |d<   | j                  | j                  ||            }nP|d   r*|d   |d<   | j	                  | j                  ||            }n!t        | j                  dz   |d   z   dz         g }i }|d   r| j                  |d	i       }n9| j                  |d	i       }| j                  |d
g       }| j                  |di       }| j                  ||      S )a2  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://developer-pro.bitmart.com/en/spot/#get-ticker-of-a-trading-pair-v3
        https://developer-pro.bitmart.com/en/futuresv2/#get-contract-details

        :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>`
        NrL   r;   r~  rJ   z  fetchTicker() does not support r!  1 markets, only spot and swap markets are acceptedr_  r}  r   )
r  r  r  r  publicGetSpotQuotationV3Tickerr.   r;   rb  rv  r=  )	rZ  r~  rd  r  r  re  tickersr  r_  s	            r\  fetch_tickerzbitmart.fetch_ticker"  s-    	V$&> &tGH::4;;wPV;WXHP F^ &tGH::4;;wPV;WXH0 tww)KKfU[n\  `S   S  T  T&>^^Hfb9F>>(FB7DnnT9b9G^^GQ3F  00r]  r}  c                    | j                          | j                  |      }d}d}|#| j                  |d      }| j                  |      }| j	                  d||      \  }}d}|dk(  r| j                  |      }n5|dk(  r| j                  |      }nt        | j                  dz   |z   dz         g }|dk(  r| j                  |dg       }n&| j                  |di       }| j                  |d	g       }i }	t        dt        |            D ]>  }
i }|dk(  r| j                  d
||
   i      }n| j                  ||
         }|d   }||	|<   @ | j                  |	d|      S )an  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://developer-pro.bitmart.com/en/spot/#get-ticker-of-all-pairs-v3
        https://developer-pro.bitmart.com/en/futuresv2/#get-contract-details

        :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   rJ   rL   z! fetchTickers() does not support r?  r_  r}  r  r~  )r  market_symbolsrs  r  handle_market_type_and_paramspublicGetSpotQuotationV3Tickersr  r.   r;   rv  rb  r  r  r=  filter_by_array_tickers)rZ  r}  rd  r!  r  r~  re  rA  r_  r  r  r  s               r\  fetch_tickerszbitmart.fetch_tickers  s    	%%g.%%gq1F[[(F99.&RXYf6>;;FCH2 V^::6BHR tww)LLtS  WJ   J  K  K6>nnXvr:G>>(FB7DnnT9b9Gq#g,' 	$AFv~**Hgaj+AB**71:6H%F#F6N	$ ++FHgFFr]  rA  c                    | j                          | j                  |      }d|d   i}d}|d   r)|||d<   | j                  | j                  ||            }nH|d   r"| j	                  | j                  ||            }n!t        | j                  dz   |d   z   d	z         | j                  |d
i       }| j                  |dd      }| j                  ||d   |      S )a~  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://developer-pro.bitmart.com/en/spot/#get-depth-v3
        https://developer-pro.bitmart.com/en/futuresv2/#get-market-depth

        :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
        r~  r;   NrJ   rA  rL   z# fetchOrderBook() does not support r!  r?  r_  r  r  )
r  r  publicGetSpotQuotationV3Booksr  publicGetContractPublicDepthr.   r;   rb  r3  parse_order_book)	rZ  r~  rA  rd  r  r  re  r_  r  s	            r\  fetch_order_bookzbitmart.fetch_order_book  s     	V$fTl
 &> #( 99$++gv:VWHF^88Wf9UVHtww)NNQWX^Q__  cV   V  W  W\ ~~h3''dK@	$$T6(+;YGGr]  tradec                 h   | j                  |g d      }| j                  |d      }|d u}d }d }d }d }	|r9| j                  |dd      }| j                  |d      }| j                  |dd      }	nY| j                  |g d      }| j                  |d	      }| j                  |d      }| j	                  | j                  |d
            }	| j                  |dd      }
| j                  |
|      }| j                  |dd      }d }|9| j                  |d      }| j                  |      }||	dk(  r|d   n|d   }||d}| j                  || j                  |g d      | j                  |dd      || j                  |      |d   ||	| j                  |g d      ||| j                  |dd      |d|      S )N)
createTimecreate_timer   r   countr   r  r!  r   )sizevolfillQtynotionalsider~  r  	paid_feesfeeCoinNamebuyr  r  r  r  )tradeIdtrade_idlastTradeIDorderIdorder_id)rM  	fillPricerl  	tradeRole	exec_type)rr  r;   orderr  r"  r~  r!  rW  rM  r  r  takerOrMakerr  )
safe_integer_nrs  r2  r4  parse_order_sider7  r  
safe_trader  safe_string_lower_2)rZ  rN  r  r  isPublicisPublicTrader  r  r!  rW  r;  feeCostStringr  feeCurrencyIdfeeCurrencyCodes                  r\  parse_tradezbitmart.parse_trade6  s   r ''/OP	##E1-!-''w:F##E84D%%eVQ7D''/IJF##E:6D##E62D(()9)9%)HID%%eXq9!!(F3**5%E$ ,,UMBM"55mDO&59U]&.PW%+C $$U,RS''y*E"Y/X&''/HI 44UKU 
  	r]  sincec                 <   | j                          | j                  |      }|d   s!t        | j                  dz   |d   z   dz         d|d   i}|||d<   | j	                  | j                  ||            }| j                  |dg       }| j                  ||||      S )	a)  
        get a list of the most recent trades for a particular symbol

        https://developer-pro.bitmart.com/en/spot/#get-recent-trades-v3

        :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 number 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>`
        rJ   z  fetchTrades() does not support r!  & orders, only spot orders are acceptedr~  r;   rA  r_  )r  r  r.   r;   publicGetSpotQuotationV3Tradesr  rv  parse_trades)	rZ  r~  rp  rA  rd  r  r  re  r_  s	            r\  fetch_tradeszbitmart.fetch_trades  s     	V$f~tww)KKfU[n\  `H   H  I  IfTl
 $GG66t{{7F7ST" ~~h3  vue<<r]  c           
         t        |t              rh| j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS | j	                  |dd      | j                  |d	d
      | j                  |dd      | j                  |dd      | j                  |dd      | j                  |dd      gS )Nr   r   rl  r   r   r   r  r  
open_priceor
  hr  lclose_pricecvolumev)
isinstancer  safe_timestampr  safe_timestamp_2safe_number_2)rZ  ohlcvr  s      r\  parse_ohlcvzbitmart.parse_ohlcv  s    V eT"##E1-  *  *  *  *  *  %%e[$?""5,<""5,<""5+s;""5-=""5(C8 r]  r   c           	      d   | j                          d}| j                  |ddd      \  }}|r| j                  d|||||d      S | j                  |      }| j	                  |      }| j                  | j                  |      }	d|d   i}
|	|	|
d<   n||
d<   |d	   r;| j                  d
|
|d      \  }
}|||
d<   || j                  |dz        dz
  |
d<   nd}||}t        ||      }| j                  | j                         dz        }||||z  z
  }||
d<   ||
d<   n@| j                  |dz        dz
  }| j                  |||z        }||
d<   t        ||      |
d<   | j                  d|
|d      \  }
}d}|d   rm| j                  |d      }|dk(  r4| j                  |d      }| j                  | j                  |
|            }nC| j!                  | j                  |
|            }n!| j#                  | j                  |
|            }| j%                  |dg       }| j'                  |||||      S )a%  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://developer-pro.bitmart.com/en/spot/#get-history-k-line-v3
        https://developer-pro.bitmart.com/en/futuresv2/#get-k-line

        :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]: timestamp of the latest candle in ms
        :param boolean [params.paginate]: *spot only* default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fr|   paginater@  r~  r;   NsteprJ   beforegMbP?rA  rG  r   afterrO  
start_timero  rL   rM  rK  r_  )r  handle_option_and_params"fetch_paginated_call_deterministicr  parse_timeframerc  r   handle_until_optionparse_to_intr  millisecondssumrs  rt  %publicGetContractPublicMarkpriceKliner  publicGetContractPublicKlinepublicGetSpotQuotationV3Klinesrv  parse_ohlcvs)rZ  r~  	timeframerp  rA  rd  r  r  durationparsedTimeframer  maxLimitnowstartendre  rM  r  s                     r\  fetch_ohlcvzbitmart.fetch_ohlcv  s     	88z[`a&::<QVX]_hjpruvvV$''	2++DOOYGfTl
 &-GFO'GFO&>"66x&RWXOGV #(  #'#4#4edl#Dq#H H} %(E##D$5$5$7$$>?C}eh..(-%&)
#))54<9A=hhueh&67(-%&)#sm
#"66z7FTYZOGV&>$$VW5E673EEdkkRY[aFbc<<T[[RX=YZ::4;;wPV;WXHD x4  	5%HHr]  c                 @   | j                          d}i }|| j                  |      }|d   |d<   d}d}| j                  d||      \  }}| j                  |g d      }	| j	                  |dg      }|dk(  rd}
| j                  d|      \  }
}|
dk(  rd	|d
<   | j                  | j                  di       }d}| j                  |d|      }||}t        ||      |d<   |||d<   |	|	|d<   | j                  | j                  ||            }nm|dk(  rJ|t        | j                  dz         |||d<   |	|	|d<   | j                  | j                  ||            }nt        | j                  dz   |z   dz         | j!                  |dg       }| j#                  ||||      S )aS  

        https://developer-pro.bitmart.com/en/spot/#account-trade-list-v4-signed
        https://developer-pro.bitmart.com/en/futuresv2/#get-order-trade-keyed

        fetch all trades made by the user
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :param boolean [params.marginMode]: *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders(only isolated margin orders are supported)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr;   r~  r{   )untilendTimero  r  rJ   isolated
iso_margin	orderModer@  rA  	startTimer  rL   z+ fetchMyTrades() requires a symbol argumentr  ro  z" fetchMyTrades() does not support / orders, only spot and swap orders are acceptedr_  )r  r  rE  rf  rt  handle_margin_mode_and_paramsrb  rT  rc  r  privatePostSpotV4QueryTradesr  r'   r;   privateGetContractPrivateTradesr.   rv  rt  )rZ  r~  rp  rA  rd  r  r  r!  re  r  r0  rT  r  defaultLimitr_  s                  r\  fetch_my_tradeszbitmart.fetch_my_tradesf  s    	[[(F &tGH99/6SYZf##F,LM6G9-6>J!%!C!COU[!\JZ''3$nnT\\?BGGH,,WgxHL}$"5(3GG ',$ %*	"88Wf9UVHV^~'2_(_`` (-% &+
#;;DKKQW<XYHtww)MMPTT  XI   I  J  Jh ~~h3  vue<<r]  r;   c                     | j                          d|i}| j                  | j                  ||            }| j                  |dg       }| j	                  |d||      S )a&  

        https://developer-pro.bitmart.com/en/spot/#order-trade-list-v4-signed

        fetch all the trades made from a single order
        :param str id: order id
        :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 to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r_  r_  N)r  !privatePostSpotV4QueryOrderTradesr  rv  rt  )	rZ  r;   r~  rp  rA  rd  r  re  r_  s	            r\  fetch_order_tradeszbitmart.fetch_order_trades  sb     	r
 99$++gv:VW~~h3  tUE::r]  c                    | j                  |di       }d }|dk(  r| j                  |dg       }n,|dk(  r| j                  |dg       }n| j                  |dg       }d|i}|dk(  rt        dt        |            D ]  }||   }| j	                  |d      }| j                  |d d	      }	| j                  |d
i       }
| j                  |di       }| j                  | j	                  |
d            }| j                  | j	                  |d            }i }| j                  |
      ||<   | j                  |      ||<   | j                  |      ||	<    |S t        dt        |            D ]  }||   }| j                  |dd      }| j	                  |d|      }| j                  |      }| j                         }| j                  |dd      |d<   | j                  |g d      |d<   |||<    | j                  |      S )Nr_  rL   rK   r}  walletrr  r   r~  _r  r  r  r;   	coin_code	availableavailable_balancefree)unAvailablefrozenfrozen_balanceused)rb  rv  r  r  rs  safe_symbolr  parse_balance_helpersafe_balancer2  accountr4  )rZ  re  
marketTyper_  r  r  r  r  r;  r~  r  r  baseCode	quoteCode	subResultbalancer  r  r  s                      r\  custom_parse_balancezbitmart.custom_parse_balance  s   ~~h3^^Hfb9F8#^^D)R8F^^D(B7F(#!1c&k* >q	++E8<))(D#>~~eVR8ugr:2243C3CD*3UV 33D4D4DUJ4WX	"$	&*&?&?&E	(#'+'@'@'G	)$!%!2!29!=v> M1c&k* ' )!//zJ
!--g{JO
..z:,,."&"4"4WkK^"_"&"4"4W>i"j&t' $$V,,r]  c                    | j                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d      |d<   | j                  |d      }| j                  |d      }t        j                  ||      |d	<   |S )
Nr  r  r  r  total_assettotalborrow_unpaidinterest_unpaiddebt)r  rs  r6   
string_add)rZ  r  r  r  interests        r\  r  zbitmart.parse_balance_helper		  s    ,,.**5(;**5+>++E=A7##E+<=!,,T8<r]  c                    | j                          d}| j                  dd|      \  }}| j                  |d      }| j                  |dd      }| j	                  |ddg      }||rd}d}|dk(  r| j                  |      }nc|dk(  r| j                  |      }nL|dk(  r| j                  |      }n5|dk(  r| j                  |      }nt        | j                  d	z   |z   d
z         | j                  ||      S )ap  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://developer-pro.bitmart.com/en/spot/#get-spot-wallet-balance-keyed
        https://developer-pro.bitmart.com/en/futuresv2/#get-contract-assets-keyed
        https://developer-pro.bitmart.com/en/spot/#get-account-balance-keyed
        https://developer-pro.bitmart.com/en/spot/#get-margin-account-details-isolated-keyed

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nr_   r0  rK   FrJ   rL   r  z! fetchBalance() does not support zE markets, only spot, swap and account and margin markets are accepted)r  rE  rs  r  rt  privateGetSpotV1Wallet%privateGetContractPrivateAssetsDetailprivateGetAccountV1Wallet%privateGetSpotV1MarginIsolatedAccountr.   r;   r  )rZ  rd  r  r0  isMarginre  s         r\  fetch_balancezbitmart.fetch_balance	  s    	
!??PTV\]
F%%fl;
>>&(E:6Hl#;<!X!J226:H6!AA&IH9$55f=H8#AA&IHtww)LLzY  ]d   d  e  e~ ((:>>r]  r  c                     | j                  |d      }| j                  |      }||| j                  |d      | j                  |d      d d dS )Nr~  maker_fee_ratetaker_fee_rate)rr  r~  r   r   r   r   )rs  r  r  )rZ  r  r  r;  r~  s        r\  parse_trading_feezbitmart.parse_trading_fee	  s^     ##C2!!(+%%c+;<%%c+;<
 	
r]  c                 (   | j                          | j                  |      }|d   s!t        | j                  dz   |d   z   dz         d|d   i}| j	                  | j                  ||            }| j                  |di       }| j                  |      S )ae  
        fetch the trading fees for a market

        https://developer-pro.bitmart.com/en/spot/#get-actual-trade-fee-rate-keyed

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        rJ   z$ fetchTradingFee() does not support r!  rr  r~  r;   r_  )r  r  r.   r;   privateGetSpotV1TradeFeer  rb  r  rZ  r~  rd  r  r  re  r_  s          r\  fetch_trading_feezbitmart.fetch_trading_fee	  s     	V$f~tww)OORXY_R``  dL   L  M  MfTl
 00Wf1MN ~~h3%%d++r]  rd  c                    d }t        |t              r|}i }| j                  |dd|      }| j                  |dd      }| j	                  |d      }| j                  ||      }| j                  ||      }| j	                  |dd      }| j	                  |d      }d }	d }
|dk(  rd	}d
}
d}	|dk(  rd	}d}	| j	                  |d      }|dk(  rd }| j                  |d      }| j                  i d|d| j                  |dd      d|d|d| j                  |      d| j                  |d      d|d|d|	d|
d| j                  | j	                  |d            d| j                  |      d|d| j                  | j	                  |d            d| j                  |d d!      d"| j                  |g d#      d$| j                  |g d%      d | j                  || j                  |d&d'            d d d(|      S ))Nr`  r_  rQ  rP  r~  r!  rJ   limit_makerrA  Tr.  iocr,  rM  zmarket priceactivation_pricer;   clientOrderIdclient_order_idrr  r  r"  lastTradeTimestampupdate_timer7  postOnlyrW  r1  r  rS  r  filled_notionalfilledNotionalr.  )	price_avgpriceAvgdeal_avg_pricefilled)filled_size
filledSize	deal_sizerk  state)	remainingrk  r  trades)r  strr2  r3  rs  r  r7  r  
safe_orderr  rc  rg  	omit_zeror4  parse_order_status_by_type)rZ  rd  r  r;   r  r;  r~  	orderTyper!  r7  r  priceStringtrailingActivationPrices                r\  parse_orderzbitmart.parse_order	  s   X eS!BEz9bA''}lK	##E84!!(F3!!&&1$$VVV<	v.= DHK5=DK&&ug6.(K"&"2"25:L"M  
" 
T//7H/Z 
 E 
 	 

 Y/ 
 !$"3"3E="I 
 f 
 D 
 ; 
  
 D))$*:*:5&*IJ 
 T^^K0 
 3 
 dnnT%5%5eV%DE 
 D&&u.?AQR 
  t))%1\]! 
" d((0Z[# 
$ 55iASASTY[celAmn+ 
, - 	r]  c                 6    ddddd}| j                  |||      S )NrZ  sell)1234rs  )rZ  rW  sidess      r\  rg  zbitmart.parse_order_sideB
  s,    	
 tT22r]  c                 z    dddddddddddddddddd}| j                  ||i       }| j                  |||      S )Nrejectedr*  closedcanceled)r  r  r  r  5678newpartially_filledr  partially_canceled)r  r  r  r   )rb  rs  )rZ  r!  rk  statusesByTypestatusess        r\  r  z"bitmart.parse_order_status_by_typeK
  sm      $*"&0  
* >>.$;&&99r]  r  c                     | j                          | j                  |      }|d   st        | j                  dz         d|d<   | j	                  |dd|d|      S )a  
        create a market buy order by providing the symbol and cost

        https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed

        :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>`
        rJ   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr*  r  rZ  N)r  r  r.   r;   create_order)rZ  r~  r  rd  r  s        r\  !create_market_buy_order_with_costz)bitmart.create_market_buy_order_with_costd
  s`     	V$f~tww)ddee6;23  5$fMMr]  r!  rW  r  rM  c                    | j                          | j                  |      }| j                  d|      }| j                  |d      }	| j	                  |g d      }
| j                  |d      }| j                  |d      }|du}|du}|
du}d}|d   r?| j                  ||||||      }|	dk(  r| j                  |      }n| j                  |      }nw| j                  ||||||      }| j                  |d	      }|| j                  |      }n;|r| j                  |      }n'|s|r| j                  |      }n| j                  |      }| j                  |d
i       }| j                  ||      }||d<   ||d<   ||d<   ||d<   |S )a	  
        create a trade order

        https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
        https://developer-pro.bitmart.com/en/spot/#new-margin-order-v1-signed
        https://developer-pro.bitmart.com/en/futuresv2/#submit-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#submit-plan-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#submit-tp-sl-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#submit-trail-order-signed

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market', 'limit' or 'trailing' for swap markets only
        :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 str [params.marginMode]: 'cross' or 'isolated'
        :param str [params.leverage]: *swap only* leverage level
        :param str [params.clientOrderId]: client order id of the order
        :param boolean [params.reduceOnly]: *swap only* reduce only
        :param boolean [params.postOnly]: make sure the order is posted to the order book and not matched immediately
        :param str [params.triggerPrice]: *swap only* the price to trigger a stop order
        :param int [params.price_type]: *swap only* 1: last price, 2: fair price, default is 1
        :param int [params.price_way]: *swap only* 1: price way long, 2: price way short
        :param int [params.activation_price_type]: *swap trailing order only* 1: last price, 2: fair price, default is 1
        :param str [params.trailingPercent]: *swap only* the percent to trail away from the current market price, min 0.1 max 5
        :param str [params.trailingTriggerPrice]: *swap only* the price to trigger a trailing order, default uses the price argument
        :param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
        :param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
        :param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rW   r   r1  	stopPricetrigger_pricer4  r5  NrJ   r  r  r_  r!  rW  r  rM  )r  r  r  rs  r4  create_spot_order_request"privatePostSpotV1MarginSubmitOrderprivatePostSpotV2SubmitOrdercreate_swap_order_request*privatePostContractPrivateSubmitTrailOrder)privatePostContractPrivateSubmitPlanOrder)privatePostContractPrivateSubmitTpSlOrder%privatePostContractPrivateSubmitOrderrb  r  )rZ  r~  r!  rW  r  rM  rd  r  r  r0  r1  r4  r5  
isStopLossisTakeProfitisTriggerOrderre  spotRequestswapRequestactivationPricer_  rd  s                         r\  r  zbitmart.create_orderv
  s   B 	V$33M6J%%fa0
))&2`a((A**63DE"$.
&d2%T1&>88tVUZ\bcKZ'BB;O<<[I88tVUZ\bcK"..{<NOO*JJ;WII+V|II+VEEkR  ~~h3  v.ff hgr]  ordersc           	         | j                          g }d}d}t        dt        |            D ]  }||   }| j                  |d      }| j	                  |      }|d   st        | j                  dz         ||}n||k7  rt        | j                  dz         | j                  |d      }	| j                  |d      }
| j                  |d	      }| j                  |d
      }| j                  |di       }| j                  ||	|
|||      }| j                  |dg      }|j                  |        |d   |d}| j                  |      }| j                  |di       }| j                  |di       }| j                  |dg       }g }t        dt        |            D ],  }||   }| j                  d|i|      }|j                  |       . |S )a  
        create a list of trade orders

        https://developer-pro.bitmart.com/en/spot/#new-batch-order-v4-signed

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]:  extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r~  rJ   z) createOrders() supports spot orders onlyz; createOrders() requires all orders to have the same symbolr!  rW  r  rM  rd  r;   )r~  orderParamsr_  orderIds)r  r  r  rs  r  r.   r;   r(   r  rb  r  rt  r  privatePostSpotV4BatchOrdersrv  r  )rZ  r!  rd  ordersRequestsr~  r  r  rawOrderr;  r!  rW  r  rM  r#  orderRequestr  re  r_  
innderDatar$  parsedOrdersr_  rd  s                          r\  create_orderszbitmart.create_orders
  s    	q#f+& 	0AayH''(;H[[*F&>"477-X#XYY~!X%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E..8R@K99(D$PVX]_jkL99\H:>L!!,/%	0( Tl)
 44W=" ~~h3^^D&"5
>>*j"=q#h-( 	'AqkGOOT7OV<E&	' r]  c                 t   | j                  |      }| j                  |d      }| j                  |d      }	|du}
|	du}|
rd}n|rd}|d   t        | j                  ||            d}| j                  |d      }| j	                  |d	      }|d
k(  }d}| j                  |d      }|dk(  }| j                  |||      \  }}|dk(  xs |dk(  }|dk(  xs |xs |}|dk(  rd|d	<   n|dk(  rd|d	<   n
|dk(  rd|d	<   |rd|d	<   | j                  |g d      }|du}| j                  |dd| j                  |            }| j                  |dd      }|du}|r| j                  ||      |d<   n9|dk(  s|r2d}||d<   | j                  ||      |d<   | j	                  |dd      |d<   |ri|s|| j                  ||      |d<   | j                  ||      |d<   | j	                  |dd      |d<   |dk(  r|rd|d <   nd|d <   n|d!k(  r|rd|d <   nd|d <   d}| j                  d"|d#      \  }}|
s|r[d$}| j	                  |dd      |d<   | j                  ||      |d<   |
r| j                  ||      |d<   n| j                  ||	      |d<   n||d%<   |dk(  r|rd|d&<   nd|d&<   n|d!k(  r|rd|d&<   nd|d&<   | j                  |d'      }|| j                  |d'      }||d(<   | j	                  |d)      }| j                  |g d*      }|| j                  |      |d)<   n|rd+|d)<   |dk7  r||d,<   | j                  ||      S )-a  
 @ignore
        create a trade order
        https://developer-pro.bitmart.com/en/futuresv2/#submit-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#submit-plan-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#submit-tp-sl-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#submit-trail-order-signed
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market', 'limit', 'trailing', 'stop_loss', or 'take_profit'
        :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 int [params.leverage]: leverage level
        :param boolean [params.reduceOnly]: *swap only* reduce only
        :param str [params.marginMode]: 'cross' or 'isolated', default is 'cross'
        :param str [params.clientOrderId]: client order id of the order
        :param str [params.triggerPrice]: *swap only* the price to trigger a stop order
        :param int [params.price_type]: *swap only* 1: last price, 2: fair price, default is 1
        :param int [params.price_way]: *swap only* 1: price way long, 2: price way short
        :param int [params.activation_price_type]: *swap trailing order only* 1: last price, 2: fair price, default is 1
        :param str [params.trailingPercent]: *swap only* the percent to trail away from the current market price, min 0.1 max 5
        :param str [params.trailingTriggerPrice]: *swap only* the price to trigger a trailing order, default uses the price argument
        :param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
        :param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
        :param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r4  r5  N	stop_losstake_profitr;   )r~  rS  r7  moder  
reduceOnlyr   r,  r   rA  GTCr   r-  rl  r  trailingTriggerPricer  trailingPercentcallback_raterM  r9  activation_price_typeexecutive_pricer  
price_typerZ  	price_wayr  rW   crossT	open_typerW  r  r  r<  )
r7  r  r0  r<  r2  r3  r1  r  r4  r5  r  r!  )r  rs  intamount_to_precisionrc  r  handle_post_onlyr4  r2  number_to_stringprice_to_precisionr  rt  r  )rZ  r~  r!  rW  r  rM  rd  r  r4  r5  r  r  r  r7  r/  isMarketOrderr  r0  isExchangeSpecificPor  isLimitOrderr1  r  r2  r3  isTrailingPercentOrderr0  r  r<  s                                r\  r  z!bitmart.create_swap_order_request  s&   : V$((A**63DE"$.
&d2D DTl00@A
 &&v}=  0(^^FL9
 $	00@TV\]&u$4$!);H;%GFOE!GFOE!GFOGFO))&2`a%T1#11&:PRdfjf{f{  }B  gC   D,,V5FX!0!<#66vuEGGZ#9D'6GO$*.*A*A&J^*_G&'/3/@/@I`bc/dG+,u0-1-D-DVU-S)*'+'>'>v|'TGO$$($5$5flA$NGL!u}+,GK(+,GK(+,GK(+,GK(
!??vW^_
FJ$($5$5flA$NGL!)-)@)@)OG%&+/+B+B6=+Y(+/+B+B6?+[(#-GK 5="#"#V^"#"#((A$YYv7F)6G%&$$VZ86  $E  F"&"7"7"AGJ"%GJ:"GFO{{7F++r]  c                 B   | j                  |      }|d   ||d}| j                  |d      }	|	dk(  rt        | j                  dz         | j	                  |d      }
|dk(  }d}|d	k(  xs |
d
k(  }| j                  |||      \  }}| j                  |ddg      }|	dk(  xs |dk(  }|dk(  xs |xs |}|r+| j                  ||      |d<   | j                  ||      |d<   n|r|dk(  r| j                  |dd      }| j                  |d      }d}| j                  |ddd      \  }}|rU||t        | j                  dz         | j                  |      }| j                  |      }t        j                  ||      }n|| j                  |      n|}| j                  |t        |d   d   | j                         |d<   n|dk(  r| j                  ||      |d<   |rd	|d<   |rd|d<   | j                  |d      }|| j                  |d      }||d<   | j#                  ||      S )aB  
 @ignore
        create a spot order request
        https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
        https://developer-pro.bitmart.com/en/spot/#new-margin-order-v1-signed
        :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 str [params.marginMode]: 'cross' or 'isolated'
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r;   )r~  rW  r!  r7  r-  zE createOrder() only accepts timeInForce parameter values of IOC or POr/  r  Nr  r   r  r,  r  rA  rS  rM  rZ  r  rV  TrW   r*  a?   createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argument or in the "notional" extra parameter(the exchange-specific behaviour)r  r  r!  r  r  )r  rs  r,   r;   rc  r=  rt  r<  r?  r2  r  r>  r6   r9  decimal_to_precisionr4   r   r  )rZ  r~  r!  rW  r  rM  rd  r  r  r7  r/  r@  r  rA  r  rB  rV  r*  amountStringr  r  s                        r\  r  z!bitmart.create_spot_order_request  s    V$Tl

 &&v}=%tww)ppqq  0( $ 5E41900@TV\]&6M:#>?u$8$%-;H;"66vvFGFO#66vuEGGu}--ffjI662481<@<Y<YZ`bo  rU  W[  =\9164H,<*477  6w  ,w  x  x'+'<'<V'D&*&;&;E&B#*#5#5lK#PAIAQt44V<X`H&*&?&?(TZ[fTghoTprv  sE  sE  'F
#"&":":66"J+GFO#GFO((A$YYv7F)6G%&{{7F++r]  c                 .   |t        | j                  dz         | j                          | j                  |      }d|d   i}| j	                  |dd      }|||d<   nt        |      |d<   | j                  |dg      }d}|d   r"| j                  | j                  ||            }n| j                  |d	d
      }| j                  |d      }	| j                  |d	d
g      }|r"| j                  | j                  ||            }nE|	r"| j                  | j                  ||            }n!| j                  | j                  ||            }|d   r|S | j                  |d      }
|
du r| j                  d|i|      S | j                  |
d      }|5| j!                  |d      }|Yt#        | j                  dz   |z   dz   |z         | j                  |
d      }|s$t#        | j                  dz   |z   dz   |z   dz         | j                  ||d   i d|      }|S )a  
        cancels an open order

        https://developer-pro.bitmart.com/en/futuresv2/#cancel-order-signed
        https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
        https://developer-pro.bitmart.com/en/futuresv2/#cancel-plan-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#cancel-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#cancel-trail-order-signed

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: *spot only* the client order id of the order to cancel
        :param boolean [params.trigger]: *swap only* whether the order is a trigger order
        :param boolean [params.trailing]: *swap only* whether the order is a stop order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr~  r;   r  r  r`  rJ   stoprE  r9  rL   r_  Tsucceedr   z  cancelOrder() failed to cancel z
 order id r  z cancelOrder() z is filled or canceled)r;   r~  rr  )r'   r;   r  r  r2  r  rt  privatePostSpotV3CancelOrderr  safe_bool_2r  )privatePostContractPrivateCancelPlanOrder*privatePostContractPrivateCancelTrailOrder%privatePostContractPrivateCancelOrderr  r  rs  r,   )rZ  r;   r~  rd  r  r  r  re  rE  r9  r_  	succeededr  rd  s                 r\  cancel_orderzbitmart.cancel_order  s<   $ >#DGG.Y$YZZV$fTl
 **6?DUV$)6G%&"%b'GJ6O#45&>88Wf9UVH&&vvyAG~~fj9HYYv	':;FII$++V]_eJfgJJ4;;W^`fKghEEdkkRY[aFbc0 &>Ox04<??D":v66OOD)4	 !!)Q/Bz"477-O#ORX#X[g#gjl#lmm__T84F"477->#>#G,#VY[#[^v#vwwrVH5Er RTZ[r]  idsc                    |t        | j                  dz         | j                          | j                  |      }|d   s!t	        | j                  dz   |d   z   dz         | j                  |d      }| j                  |dg      }d|d   i}|||d<   n||d	<   | j                  | j                  ||            }| j                  |d
i       }g }	| j                  |dg       }
t        dt        |
            D ]+  }|
|   }|	j                  | j                  |dd|             - | j                  |dg       }t        dt        |            D ]+  }||   }|	j                  | j                  |dd|             - |	S )a  
        cancel multiple orders

        https://developer-pro.bitmart.com/en/spot/#cancel-batch-order-v4-signed

        :param str[] ids: order ids
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str[] [params.clientOrderIds]: client order ids
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        z* cancelOrders() requires a symbol argumentrJ   z! cancelOrders() does not support r!  rr  clientOrderIdsr~  r;   r$  r_  
successIdsr   r  )r;   rk  failIdsfailed)r'   r;   r  r  r.   rv  rt  privatePostSpotV4CancelOrdersr  rb  r  r  r  r  )rZ  rQ  r~  rd  r  rS  r  re  r_  	allOrdersrT  r  r;   rU  s                 r\  cancel_orderszbitmart.cancel_orders  s    >#DGG.Z$Z[[V$f~tww)LLvV\~]  aI   I  J  J0@A6$4#56fTl
 %(6G$%"%GJ55dkk'66RS" ~~h3	^^D,;
q#j/* 	XAABT__B*-MvVW	X ..y"5q#g,' 	VABT__B(-KVTU	V r]  c                 h   | j                          i }d}|| j                  |      }|d   |d<   d}d}| j                  d||      \  }}|dk(  r#| j                  | j	                  ||            }|S |dk(  r;|t        | j                  dz         | j                  | j	                  ||            }|S )a  
        cancel all open orders in a market

        https://developer-pro.bitmart.com/en/spot/#cancel-all-order-v4-signed
        https://developer-pro.bitmart.com/en/futuresv2/#cancel-all-orders-signed

        :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.side]: *spot only* 'buy' or 'sell'
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr;   r~  rQ   rJ   rL   z- cancelAllOrders() requires a symbol argument)r  r  rE  privatePostSpotV4CancelAllr  r'   r;   &privatePostContractPrivateCancelOrders)rZ  r~  rd  r  r  re  r!  s          r\  cancel_all_orderszbitmart.cancel_all_ordersR  s     	[[(F &tGH99:KVU[\f6>66t{{7F7STH. - V^~'2a(abbBB4;;wX^C_`H& r]  c                    |t        | j                  dz         | j                          | j                  |      }|d   s!t	        | j                  dz   |d   z   dz         |d   ddd	}|d
k(  rd|d<   n|dk(  rd|d<   n|dk(  rd|d<   n||d<   | j                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
| j                  |
|||      S )Nz1 fetchOrdersByStatus() requires a symbol argumentrJ   z( fetchOrdersByStatus() does not support r!  rr  r;   r   rN  )r~  offsetNr*  r  rk  r  r   r  r  r_  r!  )
r'   r;   r  r  r.   privateGetSpotV3Ordersr  rb  rv  parse_orders)rZ  rk  r~  rp  rA  rd  r  r  re  r_  r!  s              r\  fetch_orders_by_statuszbitmart.fetch_orders_by_status  s   >#DGG.a$abbV$f~tww)SSV\]cVdd  hP   P  Q  QTl

 V !GHx !GHz! !GH &GH..t{{7F/KL: ~~h3h3  >>r]  c                    | j                          d}i }|| j                  |      }|d   |d<   d}d}| j                  d||      \  }}|dk(  r|t        |d      |d<   d}	| j	                  d|      \  }	}|	dk(  rd	|d
<   |||d<   | j                  |dd      }
|
| j                  |dg      }|
|d<   | j                  | j                  ||            }n|dk(  r|t        |d      |d<   | j                  |dd      }| j                  |ddg      }|r"| j                  | j                  ||            }n| j                  |dd      }| j                  |d      }| j                  |ddg      }|rd}|||d<   | j                  | j                  ||            }nt        | j                  dz   |z   dz         | j!                  |dg       }| j#                  ||||      S )a  

        https://developer-pro.bitmart.com/en/spot/#current-open-orders-v4-signed
        https://developer-pro.bitmart.com/en/futuresv2/#get-all-open-orders-keyed
        https://developer-pro.bitmart.com/en/futuresv2/#get-all-current-plan-orders-keyed

        fetch all unfilled currently open orders
        :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
        :param boolean [params.marginMode]: *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders(only isolated margin orders are supported)
        :param int [params.until]: *spot* the latest time in ms to fetch orders for
        :param str [params.type]: *swap* order type, 'limit' or 'market'
        :param str [params.order_state]: *swap* the order state, 'all' or 'partially_filled', default is 'all'
        :param str [params.orderType]: *swap only* 'limit', 'market', or 'trailing'
        :param boolean [params.trailing]: *swap only* set to True if you want to fetch trailing orders
        :param boolean [params.trigger]: *swap only* set to True if you want to fetch trigger orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr;   r~  r   rJ   r@  rA  r  r  r  r  r  r  rL   rN  rH  rE  r9  Fr  r!  z$ fetchOpenOrders() does not support r  r_  )r  r  rE  r  r  r3  rt   privatePostSpotV4QueryOpenOrdersr  rK  )privateGetContractPrivateCurrentPlanOrderr  rs  &privateGetContractPrivateGetOpenOrdersr.   r;   rv  rb  )rZ  r~  rp  rA  rd  r  r  r!  re  r0  r  	isTriggerr9  r  r_  s                  r\  fetch_open_orderszbitmart.fetch_open_orders  s<   * 	[[(F &tGH99:KVU[\f6> #&uc? J!%!C!CDUW]!^JZ''3$ ',$''CE 6I;7%*	"<<T[[RX=YZHV^ #&uc? ((CIYYv	':;FII$++V]_eJfg>>&*eD ,,V[A	6K+DE *I(&/GFOFFt{{SZ\bGcdtww)OORVV  ZK   K  L  Ln ~~h3  vue<<r]  c                 ~   | j                          d}i }|| j                  |      }|d   |d<   d}| j                  d||      \  }}|dk7  r|t        | j                  dz         ||dk(  rdnd}|||<   |dk(  rd	nd
}	| j                  |d|	      }
|
| j                  |dg      }|
||	<   d}|dk(  rCd}| j                  d|      \  }}|dk(  rd|d<   | j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }| j                  ||||      S )a7  

        https://developer-pro.bitmart.com/en/spot/#account-orders-v4-signed
        https://developer-pro.bitmart.com/en/futuresv2/#get-order-history-keyed

        fetches information on multiple closed orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest entry
        :param str [params.marginMode]: *spot only* 'cross' or 'isolated', for margin trading
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr;   r~  rd   rJ   z/ fetchClosedOrders() requires a symbol argumentr  r  r  ro  r  r  r  r  r_  )r  r  rE  r'   r;   r3  rt  r  #privatePostSpotV4QueryHistoryOrdersr  %privateGetContractPrivateOrderHistoryrv  rb  )rZ  r~  rp  rA  rd  r  r  r!  startTimeKey
endTimeKeyr  re  r0  r_  s                 r\  fetch_closed_orderszbitmart.fetch_closed_orders-  sy    	[[(F &tGH99:MvW]^f6>~'2c(cdd+/6>;L$)GL!#'6>Y

##FGZ@YYvy1F"'GJ6>J!%!C!CDWY_!`JZ''3$??GU[@\]HAA$++gW]B^_H~~h3  vue<<r]  c                 ,    | j                  d||||      S )a  
        fetches information on multiple canceled orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: max number of orders to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  )rc  )rZ  r~  rp  rA  rd  s        r\  fetch_canceled_orderszbitmart.fetch_canceled_orders[  s     **:vueVTTr]  c                    | j                          i }d}d}d}|| j                  |      }| j                  d||      \  }}|dk(  r_| j                  |d      }|s||d<   |"| j	                  | j                  ||            }n| j                  | j                  ||            }n|dk(  r|t        | j                  dz         | j                  |dd	      }	| j                  |d
      }
| j                  |d
dg      }|	rd}
|
|
|d<   |d   |d<   ||d<   | j                  | j                  ||            }| j                  |di       }| j                  ||      S )a  
        fetches information on an order made by the user

        https://developer-pro.bitmart.com/en/spot/#query-order-by-id-v4-signed
        https://developer-pro.bitmart.com/en/spot/#query-order-by-clientorderid-v4-signed
        https://developer-pro.bitmart.com/en/futuresv2/#get-order-detail-keyed

        :param str id: the id of the order
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: *spot* fetch the order by client order id instead of order id
        :param str [params.orderType]: *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
        :param boolean [params.trailing]: *swap only* set to True if you want to fetch a trailing order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   rJ   r  r_  rL   z( fetchOrder() requires a symbol argumentr9  Fr  r!  r;   r~  r`  r_  )r  r  rE  rs  !privatePostSpotV4QueryClientOrderr  privatePostSpotV4QueryOrderr'   r;   r  rt  privateGetContractPrivateOrderrb  r  )rZ  r;   r~  rd  r  r!  r  re  r  r9  r  r_  s               r\  fetch_orderzbitmart.fetch_orderf  s     	[[(F99,PVWf6> ,,V_EM %'	"(AA$++gW]B^_;;DKKQW<XYV^~'2\(\]]~~fj%@H((=IYYvZ'@AF&	$"+ &tGH"$GJ::4;;wPV;WXHf ~~h3f--r]  c                 $   | j                          | j                  |      }d}| j                  |      \  }}d| j                  ||      i}| j	                  | j                  ||            }| j                  |di       }| j                  ||      S )a  
        fetch the deposit address for a currency associated with self account

        https://developer-pro.bitmart.com/en/spot/#deposit-address-keyed

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr  r_  )r  r  r  r  !privateGetAccountV1DepositAddressr  rb  parse_deposit_address)rZ  r  rd  r  r  r  re  r_  s           r\  fetch_deposit_addresszbitmart.fetch_deposit_address  s     	==&==fEBB4Q
 99$++gv:VW ~~h3))$99r]  c           	         | j                  |d      }| j                  |dd      }|j                  d      dk  r9|j                  d      }| j                  |d      }| j                  |d      }||}| j                  |d      }| j	                  ||      }| j                  |       || j                  |d	      | j                  |      || j                  |d
d      dS )Nr  chainr  r  r   r  r   addressr  address_memomemo)rr  r  r  r}  tag)rs  r2  r  r  safe_currencycheck_addressr  )rZ  depositAddressr  r  r  r  
secondPartr}  s           r\  ry  zbitmart.parse_deposit_address  s    * %%njA
$$^WiH??5!A%$$S)E))%3J))%3J%$"">9=%%j(;7#"((6:..w7%%nnfM
 	
r]  r}  c                    | j                  ||      \  }}| j                  |       | j                          | j                  |      }d}| j	                  |      \  }}| j                  ||      |d|d}|||d<   | j                  | j                  ||            }	| j                  |	di       }
| j                  |
|      }| j                  ||||d      S )a  
        make a withdrawal

        https://developer-pro.bitmart.com/en/spot/#withdraw-signed

        :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
        :param str [params.network]: the network name for self withdrawal
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        NzTo Digital Address)r  r  destinationr}  r~  r_  )r  r}  r  )
handle_withdraw_tag_and_paramsr  r  r  r  r  !privatePostAccountV1WithdrawApplyr  rb  parse_transaction)rZ  r  r  r}  r  rd  r  r  r  re  r_  transactions               r\  r   zbitmart.withdraw  s     99#vFV7#==&==fEBB4Q/	
 ?&)GN#99$++gv:VW ~~h3,,T8<{{;)
  	r]  c                    | j                          |d}||d}d }|| j                  |      }|d   |d<   |||d<   | j                  |d      }|| j                  |d      }||d<   | j	                  | j                  ||            }	| j                  |	di       }
| j                  |
d	g       }| j                  ||||      S )
NrG  )operation_typer`  r;   r  r  r  r  r_  records)	r  r  rc  rt  )privateGetAccountV2DepositWithdrawHistoryr  rb  rv  parse_transactions)rZ  r!  r  rp  rA  rd  r  r  r  re  r_  r  s               r\  fetch_transactions_by_typez"bitmart.fetch_transactions_by_typeA  s    =E"
 }}T*H"*4.GJ#(GK !!&'2YYvw/F!&GIAA$++gW]B^_2 ~~h3..y"5&&w%GGr]  c                     | j                          d|i}| j                  | j                  ||            }| j                  |di       }| j                  |di       }| j	                  |      S )a  
        fetch information on a deposit

        https://developer-pro.bitmart.com/en/spot/#get-a-deposit-or-withdraw-detail-keyed

        :param str id: deposit id
        :param str code: not used by bitmart fetchDeposit()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r;   r_  recordr  (privateGetAccountV1DepositWithdrawDetailr  rb  r  rZ  r;   r  rd  r  re  r_  r  s           r\  fetch_depositzbitmart.fetch_depositp  q     	"
 @@WV\A]^. ~~h3h3%%f--r]  c                 ,    | j                  d||||      S )a#  
        fetch all deposits made to an account

        https://developer-pro.bitmart.com/en/spot/#get-deposit-and-withdraw-history-keyed

        :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>`
        r  r  rZ  r  rp  rA  rd  s        r\  fetch_depositszbitmart.fetch_deposits  s     ..y$ufUUr]  c                     | j                          d|i}| j                  | j                  ||            }| j                  |di       }| j                  |di       }| j	                  |      S )a  
        fetch data on a currency withdrawal via the withdrawal id

        https://developer-pro.bitmart.com/en/spot/#get-a-deposit-or-withdraw-detail-keyed

        :param str id: withdrawal id
        :param str code: not used by bitmart.fetchWithdrawal
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r;   r_  r  r  r  s           r\  fetch_withdrawalzbitmart.fetch_withdrawal  r  r]  c                 ,    | j                  d||||      S )a.  
        fetch all withdrawals made from an account

        https://developer-pro.bitmart.com/en/spot/#get-deposit-and-withdraw-history-keyed

        :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>`
        r   r  r  s        r\  fetch_withdrawalszbitmart.fetch_withdrawals  s     ..z4vVVr]  rk  c                 :    ddddddd}| j                  |||      S )Npendingrm  r  rV  )r   r  r  r  r  r  r  rZ  rk  r  s      r\  parse_transaction_statusz bitmart.parse_transaction_status  s2    
 &&99r]  r  c                 \   d }| j                  |d      }| j                  |d      }d }|
|dk7  rd}|}n|	|dk7  rd}|}| j                  |d      }| j                  |d      }| j                  |d      }	d }
|	I|	j                  d	      d
k  r5|	j	                  d      }| j                  |d
      }	| j                  |d      }
| j                  |	|      }| j                  | j                  |d            }| j                  |d      }d }|||d}| j                  |d      }| j                  |d      }| j                  |d      }i d|d|d|d|d| j                  |
      d|dd dd d|dd dd d|d|dd d|dd d d |d
k7  r|nd |d
k7  r| j                  |      nd |d!S )"Nwithdraw_id
deposit_id r   r  arrival_amount
apply_timer  r  r   r  r   rk  r  r[  tx_idr}  r~  rr  r;   r  r  addressFrom	addressTor  tagFromtagTor!  rp  txidinternalcomment)r  r"  r  )	rs  r  rc  r  r  r  r  r  r  )rZ  r  r  r;   
withdrawId	depositIdr!  r  r  r  r  r  r  rk  feeCostr  r  r}  r  s                      r\  r  zbitmart.parse_transaction  s}   0 %%k=A
$$[,?	"r)9DB#)r/DB!!+/?@%%k<@	%%k:>
	!u%)"((-!--eQ7
 ,,UA6	&&z8<..t/?/?X/VW"";6 C W5"";	:{N;
K
"
 
 f	

 t..y9
 w
 4
 
 3
 t
 T
 f
 D
 t
 D
  !
" t#
$ (1A~D4=NY/)
 	
r]  c                 T   | j                          | j                  |      }| j                  |      }|d   |d   | j                  ||      d}| j	                  | j                  ||            }| j                  |di       }	| j                  |	|      }
| j                  |
||d      S )a  
        repay borrowed margin and interest

        https://developer-pro.bitmart.com/en/spot/#margin-repay-isolated-signed

        :param str symbol: unified market symbol
        :param str code: unified currency code of the currency to repay
        :param str amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r;   r~  r  r  r_  r  r~  )r  r  r  currency_to_precision$privatePostSpotV1MarginIsolatedRepayr  rb  parse_margin_loanrZ  r~  r  r  rd  r  r  r  re  r_  r  s              r\  repay_isolated_marginzbitmart.repay_isolated_margin9  s     	V$==&Tl 00v>

 <<T[[RX=YZ ~~h3,,T8<{{;)
  	r]  c                 T   | j                          | j                  |      }| j                  |      }|d   |d   | j                  ||      d}| j	                  | j                  ||            }| j                  |di       }	| j                  |	|      }
| j                  |
||d      S )a  
        create a loan to borrow margin

        https://developer-pro.bitmart.com/en/spot/#margin-borrow-isolated-signed

        :param str symbol: unified market symbol
        :param str code: unified currency code of the currency to borrow
        :param str amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r;   r  r_  r  )r  r  r  r  %privatePostSpotV1MarginIsolatedBorrowr  rb  r  r  s              r\  borrow_isolated_marginzbitmart.borrow_isolated_margin_  s     	V$==&Tl 00v>

 ==dkk'SY>Z[ ~~h3,,T8<{{;)
  	r]  c                 X    | j                  |dd      | j                  d |      d d d d |dS )N	borrow_idrepay_id)r;   r  r  r~  r  r"  rr  )r2  r  )rZ  rr  r  s      r\  r  zbitmart.parse_margin_loan  s?     $$T;
C//h?
 	
r]  c                 *   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  |dg       }| j	                  |dg       }| j                  ||      S )a  
        fetch the rate of interest to borrow a currency for margin trading

        https://developer-pro.bitmart.com/en/spot/#get-trading-pair-borrowing-rate-and-amount-keyed

        :param str symbol: unified symbol of the market to fetch the borrow rate for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `isolated borrow rate structure <https://github.com/ccxt/ccxt/wiki/Manual#isolated-borrow-rate-structure>`
        r~  r;   r_  r}  r   )r  r  #privateGetSpotV1MarginIsolatedPairsr  rb  rv  parse_isolated_borrow_rate)	rZ  r~  rd  r  r  re  r_  r}  
borrowRates	            r\  fetch_isolated_borrow_ratez"bitmart.fetch_isolated_borrow_rate  s     	V$fTl
 ;;DKKQW<XYB ~~h3..y"5^^GQ3
..z6BBr]  rr  c           
      r   | j                  |d      }| j                  ||      }| j                  |di       }| j                  |di       }| j                  |d      }| j                  |d      }|| j                  |      | j	                  |d      | j                  |      | j	                  |d      dd d |d	S )Nr~  r  r  r  hourly_interesti6 )	r~  r  baseRater  	quoteRateperiodr  r"  rr  )rs  r  rb  r  r  )	rZ  rr  r  r;  r~  baseData	quoteDatar  r  s	            r\  r  z"bitmart.parse_isolated_borrow_rate  s    0 ##D(3!!(F3>>$3NN4"5	!!(J7""9j9++F3((3DE,,W5)))5FG

 
	
r]  c                     | j                          | j                  |      }| j                  |di       }| j                  |dg       }| j	                  |      S )a  
        fetch the borrow interest rates of all currencies, currently only works for isolated margin

        https://developer-pro.bitmart.com/en/spot/#get-trading-pair-borrowing-rate-and-amount-keyed

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `isolated borrow rate structures <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
        r_  r}  )r  r  rb  rv  parse_isolated_borrow_rates)rZ  rd  re  r_  r}  s        r\  fetch_isolated_borrow_ratesz#bitmart.fetch_isolated_borrow_rates  sX     	;;FCB ~~h3..y"5//88r]  fromAccount	toAccountc                    | j                          | j                  |      }| j                  ||      }||d   d}| j                  |      }	| j                  |      }
|dk(  r|dk(  rd|d<   |
|d<   nC|dk(  r>d	|d
<   n8|dk(  r|dk(  rd|d<   |	|d<   n#|dk(  rd|d
<   nt	        | j
                  dz         d}|dk(  s|dk(  r"| j                  | j                  ||            }n+|dk(  s|dk(  r!| j                  | j                  ||            }| j                  |di       }| j                  | j                  ||      d| j                  | j                  |dd            i      S )a  
        transfer currency internally between wallets on the same account, currently only supports transfer between spot and margin

        https://developer-pro.bitmart.com/en/spot/#margin-asset-transfer-signed
        https://developer-pro.bitmart.com/en/futuresv2/#transfer-signed

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r;   )r  r  rJ   rK   inrW  r~  rL   spot_to_contractr!  outcontract_to_spotz? transfer() requires either fromAccount or toAccount to be spotNr_  rk  r  message)r  r  r  convert_type_to_accountr'   r;   'privatePostSpotV1MarginIsolatedTransferr  $privatePostAccountV1TransferContractrb  parse_transferparse_transfer_statusr2  )rZ  r  r  r  r  rd  r  amountToPrecisionr  fromIdtoIdre  r_  s                r\  r   zbitmart.transfer+  s    	==& 66tVD' 
 --k:++I6& H$"&$(!f$"4& h&"'$*!&"4#DGG.o$opp8#h)>CCDKKPWY_D`aHV#f)<@@WV\A]^H2 ~~h3{{4..tX>d001C1CHfV_1`aA
  	r]  c                 4    dddd}| j                  |||      S )Nrm  )r   OKFINISHEDr  r  s      r\  r  zbitmart.parse_transfer_statusr  s)    

 &&99r]  c                 2    ddd}| j                  |||      S )NrJ   rL   r  r  r  rZ  r!  typess      r\  parse_transfer_to_accountz!bitmart.parse_transfer_to_accountz  &     & &
 tT22r]  c                 2    ddd}| j                  |||      S )NrL   rJ   r  r  r  s      r\  parse_transfer_from_accountz#bitmart.parse_transfer_from_account  r  r]  r   c                    | j                  |d      }| j                  |d      }| j                  |d      || j                  |      | j                  ||      | j	                  |d      | j                  | j                  |d            | j                  | j                  |d            | j                  | j                  |d            dS )Nr  r  transfer_idr  r!  r  )r;   r  r"  r  r  r  r  rk  )rs  rc  r  r  r  r  r  r  )rZ  r   r  r  r  s        r\  r  zbitmart.parse_transfer  s    4 %%h
;
%%h<	""8];"Y///
HE&&x:;;D<L<LXW]<^_778H8HSY8Z[001A1A(G1TU	
 		
r]  c                    | j                          |d}| j                  |dd      |d}d}|| j                  |      }|d   |d<   |||d<   |||d	<   | j                  |d
      }| j                  |d|      }| j                  |d
g      }|||d<   | j	                  | j                  ||            }	| j                  |	di       }
| j                  |
dg       }| j                  ||||      S )a"  
        fetch a history of internal transfers made on an account, only transfers between spot and swap are supported

        https://developer-pro.bitmart.com/en/futuresv2/#get-transfer-list-signed

        :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 transfer structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.page]: the required number of pages, default is 1, max is 1000
        :param int [params.until]: the latest time in ms to fetch transfers for
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nr   pager   )r  rA  r;   r  
time_startrA  r  time_endr_  r  )	r  rc  r  rt  (privatePostAccountV1TransferContractListr  rb  rv  parse_transfers)rZ  r  rp  rA  rd  r  r  r  r  re  r_  r  s               r\  fetch_transferszbitmart.fetch_transfers  s     	=E%%ffa8
 }}T*H"*4.GJ$)GL!$GG!!&'2##FJ>6G9-")GJ@@WV\A]^( ~~h3..y"5##GXueDDr]  c                 |   |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   |||d<   | j	                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
| j                  |
|      }| j                  ||||      S )a  
        fetch the interest owed by the user for borrowing currency for margin trading

        https://developer-pro.bitmart.com/en/spot/#get-borrow-record-isolated-keyed

        :param str code: unified currency code
        :param str symbol: unified market symbol when fetch interest in isolated markets
        :param int [since]: the earliest time in ms to fetch borrrow interest for
        :param int [limit]: the maximum number of structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
        z1 fetchBorrowInterest() requires a symbol argumentr~  r;   r`  r  r_  r  )
r'   r;   r  r  *privateGetSpotV1MarginIsolatedBorrowRecordr  rb  rv  parse_borrow_interestsfilter_by_currency_since_limit)rZ  r  r~  rp  rA  rd  r  r  re  r_  rowsr  s               r\  fetch_borrow_interestzbitmart.fetch_borrow_interest  s     >#DGG.a$abbV$fTl
  GCL$)GL!BB4;;wX^C_`, ~~h3~~dIr2..tV<228T5%PPr]  c                 b   | j                  |d      }| j                  ||      }| j                  |d      }|| j                  |d      | j                  | j                  |d            | j	                  |d      | j	                  |d      | j	                  |d      d|| j                  |      d	S )	Nr~  rQ  r  interest_amountr  borrow_amountr  )	rr  r~  r  r  interestRateamountBorrowedr0  r  r"  )rs  r7  rc  r  r  r  )rZ  rr  r  r;  r  s        r\  parse_borrow_interestzbitmart.parse_borrow_interest  s     ##D(3!!(F3%%dM:	&&vx8//0@0@z0RS((/@A ,,T3DE"..t_E$"Y/

 
	
r]  c                    | j                          | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||            }| j                  |di       }| j                  ||      S )al  
        Retrieves the open interest of a currency

        https://developer-pro.bitmart.com/en/futuresv2/#get-futures-openinterest

        :param str symbol: Unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
        rj  z3 fetchOpenInterest() supports contract markets onlyr~  r;   r_  )r  r  r(   r;   #publicGetContractPublicOpenInterestr  rb  parse_open_interestr  s          r\  fetch_open_interestzbitmart.fetch_open_interest8  s     	V$j!TWW'\\]]fTl
 ;;DKKQW<XY ~~h3''f55r]  c           	          | j                  |d      }| j                  |d      }| j                  | j                  ||      | j	                  |d      | j	                  |d      || j                  |      |d|      S )Nr  r~  open_interestopen_interest_value)r~  openInterestAmountopenInterestValuer  r"  rr  )rc  rs  safe_open_interestr  r  r  )rZ  r  r  r  r;   s        r\  r  zbitmart.parse_open_interestZ  s     %%h<	h1&&&&r62"&"2"28_"M!%!1!1(<Q!R"Y/(
  	r]  r<  c                 r   |t        | j                  dz         d}| j                  d|      \  }}| j                  d|dddg       | j	                          | j                  |      }|d   st        | j                  dz         |d	   t        |      |d
}| j                  | j                  ||            S )a  
        set the level of leverage for a market

        https://developer-pro.bitmart.com/en/futuresv2/#submit-leverage-signed

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'isolated' or 'cross'
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr   r0  r  r9  rL   z+ setLeverage() supports swap contracts onlyr;   )r~  r<  r:  )
r'   r;   r  check_required_argumentr  r  r)   r  (privatePostContractPrivateSubmitLeverager  )rZ  r<  r~  rd  r0  r  r  s          r\  set_leveragezbitmart.set_leveragen  s     >#DGG.Y$YZZ
!??vV
F$$]Jz[bNcdV$f~DGG&SSTTTlH#

 <<T[[RX=YZZr]  c                    | j                          | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||            }| j                  |di       }| j                  ||      S )ap  
        fetch the current funding rate

        https://developer-pro.bitmart.com/en/futuresv2/#get-current-funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        rL   z0 fetchFundingRate() supports swap contracts onlyr~  r;   r_  )r  r  r)   r;   "publicGetContractPublicFundingRater  rb  parse_funding_rater  s          r\  fetch_funding_ratezbitmart.fetch_funding_rate  s     	V$f~DGG&XXYYfTl
 ::4;;wPV;WX ~~h3&&tV44r]  c           
         |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   | j	                  | j                  ||            }| j                  |di       }| j                  |dg       }	g }
t        dt        |	            D ]u  }|	|   }| j                  |d      }| j                  ||dd	      }| j                  |d
      }|
j                  ||| j                  |d      || j                  |      d       w | j!                  |
d      }| j#                  ||d   ||      S )a  
        fetches historical funding rate prices

        https://developer-pro.bitmart.com/en/futuresv2/#get-funding-rate-history

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: not sent to exchange api, exchange api always returns the most recent data, only used to filter exchange response
        :param int [limit]: the maximum amount of funding rate structures to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        z5 fetchFundingRateHistory() requires a symbol argumentr~  r;   rA  r_  r  r   r  rL   funding_timefunding_rate)rr  r~  fundingRater  r"  r  )r'   r;   r  r  )publicGetContractPublicFundingRateHistoryr  rb  rv  r  r  rs  r  rc  r  r  r  sort_byfilter_by_symbol_since_limit)rZ  r~  rp  rA  rd  r  r  re  r_  r  ratesr  r  r;  symbolInnerr  sorteds                    r\  fetch_funding_rate_historyz"bitmart.fetch_funding_rate_history  sc    >#DGG.e$effV$fTl
 $GGAA$++gW]B^_" ~~h3fb1q#f+& 	A1IE''x8H**8VS&IK))%@ILL%#//~F& LL3 	 e[1009I5RWXXr]  c                 :   | j                  |d      }| j                  |d      }i d|d| j                  ||      dd dd dd dd d|d| j                  |      d	| j	                  |d
      dd dd dd dd dd d| j	                  |d      dd dd dd iS )Nr~  r  rr  	markPricer1  r  estimatedSettlePricer"  r  expected_ratefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRate
rate_valuepreviousFundingTimestamppreviousFundingDatetimeinterval)rs  rc  r  r  r  )rZ  rj  r  r;  r  s        r\  r  zbitmart.parse_funding_rate  s6    ##Hh7%%h<	
H
d&&x8
 
 $	

 D
 #D
 
 Y/
 4++HoF
 
 t
 t
 #D
 "4
 "4#3#3Hl#K
  '!
" &t#
$ %
 	
r]  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  ||      S )a  
        fetch data on a single open contract trade position

        https://developer-pro.bitmart.com/en/futuresv2/#get-current-position-keyed

        :param str symbol: unified market symbol of the market the position is held in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        r~  r;   r_  r   )r  r  !privateGetContractPrivatePositionr  rv  rb  parse_position)rZ  r~  rd  r  r  re  r_  firsts           r\  fetch_positionzbitmart.fetch_position  s     	V$fTl
 99$++gv:VW< ~~h3tQ+""5&11r]  c                    | j                          d}d}|.t        |      }| j                  |d      }| j                  |      }i }|dk(  r|d   |d<   | j	                  | j                  ||            }| j                  |dg       }g }	t        dt        |            D ]%  }
|	j                  | j                  ||
                ' | j                  |      }| j                  |	d|d      S )a  
        fetch all open contract positions

        https://developer-pro.bitmart.com/en/futuresv2/#get-current-position-keyed
        https://developer-pro.bitmart.com/en/futuresv2/#get-current-position-v2-keyed

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   r   r;   r~  r_  F)r  r  rs  r  #privateGetContractPrivatePositionV2r  rv  r  r  r/  rD  filter_by_array_positions)rZ  r}  rd  r  symbolsLengthr0  r  re  	positionsr  r  s              r\  fetch_positionszbitmart.fetch_positions5  s     	LM$$Wa0E[['FA &tGH;;DKKQW<XY< NN8VR8	q#i.) 	=AMM$--il;<	=%%g.--fhOOr]  positionc                    | j                  |d      }| j                  ||      }|d   }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	t        j                  ||      }
t        j                  ||	      }| j                  i d|dd d|d|d	| j                  |      d
d dd d|dk(  rdndd| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd d| j                  |      d| j                  |d      d| j                  |	      dd d | j                  |      | j                  |
      | j                  |d      | j                  |d      d d d | j                  |      d d d      S )Nr~  r  position_typemaintenance_margincurrent_valueposition_crossrr  r;   r"  lastUpdateTimestampr8  rW  r   longshort	contractscurrent_amountr  
entryPriceentry_pricer   
mark_price	lastPricerV  r<  
collateralinitialMarginunrealized_valuerealized_value)initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentageunrealizedPnlrealizedPnlliquidationPricer0  r   marginRatior4  r5  )	rs  r7  rc  r6   
string_divsafe_positionr  r  rY  )rZ  r8  r  r;  r~  r  rW  rL  rV  rG  rM  rQ  s               r\  r/  zbitmart.parse_positionp  sf   . ##Hh7!!(F3!%%h<	  ?; ,,X7KL##Ho>%%h0@A
&-&8&89JH&U#(():JG!! #
H#
$#
 f#
 	#

 Y/#
 "4#
 d#
 tqyFw#
 ))(4DE#
 D,,V^D#
 $**8]C#
 ))(LA#
 #
 ))(3#
 ((:>#
  $++J7!#
" T##
$ (,!%!2!23D!E+/+<+<=X+Y!--h8JK++H6FG $,,[9!#9#
  	r]  c                    |t        | j                  dz         | j                          | j                  |      }|d   st	        | j                  dz         d|d   i}|||d<   | j                  d||      \  }}| j                  | j                  ||            }| j                  |dg       }g }	t        d	t        |            D ]0  }
||
   }| j                  |d
      }|dk(  s |	j                  |       2 | j                  |	|||      S )az  
        retrieves the users liquidated positions

        https://developer-pro.bitmart.com/en/futuresv2/#get-order-history-keyed

        :param str symbol: unified CCXT market symbol
        :param int [since]: the earliest time in ms to fetch liquidations for
        :param int [limit]: the maximum number of liquidation structures to retrieve
        :param dict [params]: exchange specific parameters for the bitmart api endpoint
        :param int [params.until]: timestamp in ms of the latest liquidation
        :returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
        z1 fetchMyLiquidations() requires a symbol argumentrL   z1 fetchMyLiquidations() supports swap markets onlyr~  r;   r  ro  r_  r   r!  	liquidate)r'   r;   r  r  r.   r  rl  r  rv  r  r  rs  r  parse_liquidations)rZ  r~  rp  rA  rd  r  r  re  r_  r  r  r  checkLiquidations                r\  fetch_my_liquidationszbitmart.fetch_my_liquidations  s&    >#DGG.a$abbV$f~tww)\\]]fTl
 $)GL!22:wO==dkk'SY>Z[4 ~~h3q#d)$ 	%AGE#//v>;.e$		%
 &&vvueDDr]  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t        j                  ||      }t        j                  ||      }	| j	                  || j                  ||      | j                  |      | j                  |      | j                  |      | j                  |      | j                  |	      || j                  |      d	      S )Nr~  r  r  r  r  )	rr  r~  rA  r  rM  	baseValue
quoteValuer  r"  )rs  rc  r6   r9  safe_liquidationr  rY  r  )
rZ  liquidationr  r;  r  contractsStringcontractSizeStringr  baseValueStringquoteValueStrings
             r\  parse_liquidationzbitmart.parse_liquidation  s   & ##K:%%k=A	**;D!--fnE&&{4DE!,,_>PQ"--o{K$$&&x8**?; --.@A&&{3**?;++,<="Y/
&
 
 
	r]  c                 <   | j                          | j                  |      }|d   s!t        | j                  dz   |d   z   dz         | j	                  |d      }	| j	                  |d      }
| j                  |g d      }| j                  |di       }| j                  |d	i       }| j	                  |d
      }| j	                  |d
      }|du}|	du}|
du}|du}|du}|dk(  }d|d   i}| j	                  |d      }|| j                  |d      }||d<   |||d<   | j                  |g d      }d}|s|s|r-| j                  |dd      |d<   || j                  ||      |d<   |r=||d<   | j                  ||      |d<   | j                  | j                  ||            }nU|s|rT||d<   |r| j                  ||	      |d<   n| j                  ||
      |d<   | j                  | j                  ||            }n|s|r{|r,| j                  |dd      |d<   | j                  ||      |d<   n+| j                  |dd      |d<   | j                  ||      |d<   | j                  | j                  ||            }n~|rd| j                  |      |d<   || j                  ||      |d<   || j                  ||      |d<   | j!                  | j                  ||            }nt        | j                  dz         | j                  |di       }| j#                  ||      S ) a  
        edits an open order

        https://developer-pro.bitmart.com/en/futuresv2/#modify-plan-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#modify-tp-sl-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#modify-preset-plan-order-signed
        https://developer-pro.bitmart.com/en/futuresv2/#modify-limit-order-signed

        :param str id: order id
        :param str symbol: unified symbol of the market to edit 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, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.triggerPrice]: *swap only* the price to trigger a stop order
        :param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
        :param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
        :param str [params.stopLoss.triggerPrice]: *swap only* the price to trigger a preset stop-loss order
        :param str [params.takeProfit.triggerPrice]: *swap only* the price to trigger a preset take-profit order
        :param str [params.clientOrderId]: client order id of the order
        :param int [params.price_type]: *swap only* 1: last price, 2: fair price, default is 1
        :param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rL   z editOrder() does not support r!  z) markets, only swap markets are supportedr4  r5  r  stopLoss
takeProfitr1  NrA  r~  r;   r  r  r`  )r1  r  r4  r5  rd  re  r7  r   r6  r  categorypreset_stop_loss_price_typepreset_stop_loss_pricepreset_take_profit_price_typepreset_take_profit_pricerS  rM  zK editOrder() only supports limit, trigger, stop loss and take profit ordersr_  )r  r  r.   r;   rs  r4  rb  rt  rc  r?  )privatePostContractPrivateModifyPlanOrderr  )privatePostContractPrivateModifyTpSlOrder/privatePostContractPrivateModifyPresetPlanOrderr  r<  *privatePostContractPrivateModifyLimitOrderr  )rZ  r;   r~  r!  rW  r  rM  rd  r  r4  r5  r1  rd  re  presetStopLosspresetTakeProfitr  r  r  isPresetStopLossisPresetTakeProfitrB  r  r  re  r_  s                             r\  
edit_orderzbitmart.edit_order  s   4 	V$f~tww)IIFSYNZ  ^I   I  J  J((A**63DE))&2`a>>&*b9^^FL"=
))(NC++JG%T1"$.
&d2)5-T9fTl
 ((A$YYv7F)6G%&>"$GJ6#~Z<$($5$5flA$NGL! -1-D-DVU-S)*"GFO'+'>'>v|'TGO$EEdkkRY[aFbcH <"&GJ+/+B+B6=+Y(+/+B+B6?+[(EEdkkRY[aFbcH !39=9J9J6S_ab9c56484K4KFTb4c01;?;L;LVUacd;e786:6M6MfVf6g23KKDKKX_agLhiH "&"3"3B"7GJ!"&":":66"J #'#:#:65#I FFt{{SZ\bGcdHtww)vvww~~h3f--r]  c                    | j                          d}|| j                  |      }i }| j                  d||      \  }}| j                  dd|||      }| j	                  |      }| j                  |dg       }	| j                  |	|||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://developer-pro.bitmart.com/en/futuresv2/#get-transaction-history-keyed

        :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 exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest ledger entry
        :returns dict[]: a list of `ledger structures <https://docs.ccxt.com/#/?id=ledger>`
        Nro  r   r_  )r  r  r  fetch_transactions_request+privateGetContractPrivateTransactionHistoryrv  parse_ledger)
rZ  r  rp  rA  rd  r  r  transactionsRequestre  r_  s
             r\  fetch_ledgerzbitmart.fetch_ledger  s     	}}T*H22:wO"==aueU[\CCDWX& ~~h3  x>>r]  itemc                     | j                  |d      }d }t        j                  |d      rd}t        j                  d|      }nd}| j                  |d      }| j	                  ||      }| j                  |d      }| j                  |d      }| j                  || j                  |d	      |d d | j                  |d
      | j                  |      |d   | j                  |      || j                  |      d d d d d|      S )Nr  r   r  z-1r  assettimer!  tran_idr\  r  )rr  r;   	directionr  referenceAccountreferenceIdr!  r  r  r  r"  r  r  rk  r  )
rs  r6   	string_ler9  r  rc  safe_ledger_entryparse_ledger_entry_typerY  r  )rZ  rz  r  r  r  r  r  r!  s           r\  parse_ledger_entryzbitmart.parse_ledger_entry  s    !!$1	VS)I''f5FI%%dG4
%%j(;%%dF3	f-%%""43" $++D)<006 (''/"Y/'
  ! 	r]  c                 8    dddddd}| j                  |||      S )Nr  rN  r   
settlement)zCommission FeezFunding FeezRealized PNLTransferzLiquidation Clearancer  )rZ  r!  
ledgerTypes      r\  r  zbitmart.parse_ledger_entry_type  s/    # #"%1

 
D$77r]  flowTypec                     i }|||d<   d }|| j                  |      }|d   |d<   |||d<   |||d<   | j                  d||      \  }}| j                  ||      S )N	flow_typer;   r~  r  	page_sizero  )r  r  r  )rZ  r  r~  rp  rA  rd  r  r  s           r\  ru  z"bitmart.fetch_transactions_request  s    #+GK [[(F &tGH$)GL!#(GK 22:wO{{7F++r]  c                    | j                          d}|| j                  |      }i }| j                  d||      \  }}| j                  d||||      }| j	                  |      }| j                  |dg       }	| j                  |	|||      S )a  
        fetch the history of funding payments paid and received on self account

        https://developer-pro.bitmart.com/en/futuresv2/#get-transaction-history-keyed

        :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 exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch funding history for
        :returns dict[]: a list of `funding history structures <https://docs.ccxt.com/#/?id=funding-history-structure>`
        Nro  r   r_  )r  r  r  ru  rv  rv  parse_funding_histories)
rZ  r~  rp  rA  rd  r  r  rx  re  r_  s
             r\  fetch_funding_historyzbitmart.fetch_funding_history  s     	[[(F22:wO"==aPUW]^CCDWX& ~~h3++D&%GGr]  c           
      "   | j                  |d      }| j                  |d      }| j                  |d      }|| j                  ||d d      | j                  |      || j	                  |      | j                  |d      | j                  |d      dS )Nr~  r|  r}  rL   r~  r  )rr  r~  r  r  r"  r;   r  )rs  rc  r  r  r  r  )rZ  rj  r  r;  r  r  s         r\  parse_funding_historyzbitmart.parse_funding_history  s     ##Hh7%%h8
%%h7	&&xvF++J7"Y/""8Y7&&x:
 	
r]  c                     g }t        dt        |            D ](  }||   }|j                  | j                  ||             * | j	                  |d      }| j                  |||      S )Nr   r  )r  r  r  r  r  filter_by_since_limit)	rZ  rA  r  rp  rA  r  r  rj  r  s	            r\  r  zbitmart.parse_funding_histories8  sl    q#i.) 	HA |HMM$44XvFG	H fk2))&%??r]  c                    | j                          d }|| j                  |      }|d   }|g}| j                  |      }| j                  |di       }| j	                  |dg       }	| j                  |	|d      }
g }t        dt        |
            D ]:  }|
|   }|d u xs |d   |k(  }|d u xs |d   |k(  }|s'|s*|j                  |       < |S )Nr  r_  r  Fr   noter  )	r  r  &privateGetAccountV1WithdrawAddressListrb  rv  parse_deposit_addressesr  r  r  )rZ  r  r  r  rd  codesr  re  r_  r  allAddresses	addressesr  r}  	noteMatchnetworkMatchs                   r\  fetch_withdraw_addressesz bitmart.fetch_withdraw_addresses@  s    }}T*HF#DFE>>vF* ~~h3~~dFB/33D%G	q#l+, 	*A"1oGC76?d+BI'4/WWY5G;5VL\  )	* r]  r8  c                 ~    | j                          d}|rd}nd}d|i}| j                  | j                  ||            S )a  
        set hedged to True or False for a market

        https://developer-pro.bitmart.com/en/futuresv2/#submit-leverage-signed

        :param bool hedged: set to True to use dualSidePosition
        :param str symbol: not used by bingx setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        N
hedge_modeone_way_modeposition_mode)r  )privatePostContractPrivateSetPositionModer  )rZ  r8  r~  rd  positionModer  s         r\  set_position_modezbitmart.set_position_modeh  sM     	'L)L\
 ==dkk'SY>Z[[r]  c                 |    | j                  |      }| j                  |d      }| j                  |d      }||dk(  dS )a  
        fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets

        https://developer-pro.bitmart.com/en/futuresv2/#get-position-mode-keyed

        :param str symbol: not used
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        r_  r  r  )rr  r8  )(privateGetContractPrivateGetPositionModerb  rs  )rZ  r~  rd  re  r_  r  s         r\  fetch_position_modezbitmart.fetch_position_mode  sM     @@H ~~h/''o>#|3
 	
r]  c                 B    | j                         | j                  d   z
  S )Nr$  )r  rT  )rZ  s    r\  noncezbitmart.nonce  s       "T\\2B%CCCr]  r   GETc                 ,   |j                  d      }| j                  |dd      }|dk(  s|dk(  rdnd}	| j                  | j                  d   |	         }
|
dz   | j	                  ||      z   }| j                  || j                  |            }d}|dk(  xs |d	k(  }|r|r| j                  |      }|d
|z   z  }|dk(  r| j                          t        | j                               }| j                  | j                  dd      }| j                  ||dd}|s| j                  |      }|}|dz   | j                  z   dz   |z   }| j                  | j!                  |      | j!                  | j"                        t$        j&                        }||d<   ||||dS )Nr  r   rJ   r  rL   r   r  r  DELETE?r   r+  r"  zapplication/json)zX-BM-KEYzX-BM-TIMESTAMPzX-BM-BROKER-IDzContent-Type#z	X-BM-SIGN)r   methodbodyheaders)r  rs  implode_hostnamer   implode_paramsrt  extract_params	urlencodecheck_required_credentialsr  r  rT  r   jsonr   hmacencoder   hashlibsha256)rZ  pathr   r  rd  r  r  r  rf  r  baseUrlr   queryqueryStringgetOrDeleter  r+  auth	signatures                      r\  signzbitmart.sign  s   

3##E1f5$.(i2Gf''		%(8(@Amd11$??		&$"5"5d";<?Fh,>"nnU3s[(()++-DJJL)I''jBSTH KK"+"* 2	G yy'"s?TXX-3kAD		$++d"3T[[5Mw~~^I#,GK fdwOOr]  reasonr   r  r  r  c
                    |y | j                  |d      }
|
d uxr |
dk7  xr |
dk7  }| j                  |d      }|d uxr |dk7  }|s|r| j                  dz   |z   }| j                  | j                  d   |
|       | j                  | j                  d   |
|       | j                  | j                  d   ||       | j                  | j                  d   ||       t        |      y )	Nr  rm  successr  r    r  r  )r6  rs  r;   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr#   )rZ  r  r  r   r  r  r  re  requestHeadersrequestBodyr  isErrorMessage	errorCodeisErrorCodefeedbacks                  r\  handle_errorszbitmart.handle_errors  s     ((9=!-_GtO_'U^J^$$Xv6	 ,G93F.ww}t+H001I7T\]001I7T\]001I9V^_001I9V^_))r]  )N)NNN)__name__
__module____qualname__r   rX  r   rf  r{  r"   r    r  r  r   r  r   r  r   r  r  r  r	   r  r  dictr   r=  rB  r   r   rH  r   rM  r   ro  ru  r  r  r  r  r  r   r  r  r  r   r  r  r   r  rg  r  floatr  r   r   r   r  r   r+  r  r  rP  rY  r]  rc  ri  ro  rq  rv  r
   rz  ry  r   r   r  r  r  r  r  r  r  r  r  r  r   r  r  r   r  r!   r   r  r  r  r  r  r   r  r  r  r  r  r   r  r  r  r1  r   r7  r/  rX  rb  rs  r   ry  r  r  ru  r   r  r  r  r  boolr  r  r  r  r;  r  __classcell__)r[  s   @r\  r8   r8   !   s   M# M^ !# 6s 6. #% =
~ )+ atO/D aF -/ q43H qf $& 1$v, 1  ') \Z \|D# DTW D\_ D8 79 %
# %
N
 
, <>  5s  5DY4 Y Y6 Yv 02 ]13 ]1f ]1~ 04B hGW hG7 hGT :>b IHs IH3 IHY IHVd dv d dL 6:UW '=3 '=s '=# '=\`af\g '=R< <4 <| 26DW[df aI# aIc aIQT aIkoptku aIF -1tRV_a h=c h= h=C h=T 9=4^bkm ;S ;# ;S ;X[ ;*"-H "-H $& }?( }?~
T 
6 
EX 
& 57 , ,;N ,Bz zv z zx3:2 RT N N5 N$ gksu S3 Si Sy SRW S`c Sj @B >D$6 >@ tx  AC x, x,9 x,I x,_d x,mp x,t tx  AC ?, ?,9 ?,I ?,_d ?,mp ?,B 37r Rs RC Rh ;?r 6c 6C 6dSXk 6p /32 - -^ <@daenp 3?S 3? 3?[^ 3?j /3TXac u= u=3 u=c u=hlmrhs u=n 154VZce ,=# ,=S ,=PS ,=jnotju ,=\ 37TX\eg 	UC 	Us 	URU 	U 26b `.c `.3 `.D 79  :#  :^  :D&
n &
P DHPR -S -% -# -Wb -^ <@daenp -HS -H -H[^ -H^ 26b (. (.3 (.T *.Dt\^ V3 Vc V Vcghsct V 59 (.3 (.c (.T -1tRV_a Wc W WC Wfjkvfw W	:s 	:L
T L
X L
Q\ L
\ LN $C $s $L TV $S $ $U $L
 
0 >@ 3C 3CDV 3Cj(
t (
V (
Oa (
T 24 -98K -9^ [] ES E% Ec Ec Ean EN:C :C :33%
t %
x %
= %
N +/TPT]_ 8EC 8Es 8E# 8Edhivdw 8Et 15DW[jnwy 1Q# 1Qc 1QQT 1Qdg 1Q  C  DR  S 1Qf
$ 
 
. 
8 79  6#  6DF ( 9=R [S [# [8 68  5  5K  5D 8<$]ajl 6Y 6YC 6YWZ 6Yp
6 
[ 
@ 24 /2S /2b 26b 9Pw 9PT(^ 9Pv>t >V >@ 37TX\eg :EC :Es :ERU :Ex$V $L `drv  @B u.S u.# u.Y u.i u.Y\ u.lo u.  GL u.n (,$TZ\ (? (?C (?s (?aefqar (?T't 'x '; 'R8 :>T`dsw  AC ,3 ,s ,Z] ,mp , 37TX\eg (HC (Hs (HRU (Hlpq  mA (HT
f 
2@S @X[ @gklzg{ @ 8<VX &S &P =A \ \c \@ 15R 
# 
8D &eBSW P@# s  c TX `c r]  r8   )=ccxt.base.exchanger   ccxt.abstract.bitmartr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   typingr"   ccxt.base.errorsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   ccxt.base.decimal_to_precisionr4   r5   ccxt.base.preciser6   r8    r]  r\  <module>r     s    ( -  m  m  m  m  m  m  m  m  * 0 - - . ' & . + ) * ) ) . 1 * ) 3 4 %ASh ASr]  