
    ei)                       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<dS )    )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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d0e3fd1Z4di fded2e5d3e6d4e3d5e7f
d6Z8i fd7ee9         fd8Z:di fded2e5d3e6d4e3d5e7f
d9Z;di fded2e5d3e6d4e3d5e7f
d: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dAZBdddi fdededefdBZCdi fd$edefdCZDi fdedeEfdDZFddeEfdEZGdi fded4e3dFedGedeHf
dHZIdddi fdededefdIZJdi fd$edefdJZKdddi fdedededeeH         fdKZLdi fd$edefdLZMdddi fdedededeeH         fdMZNdNefdOZOddPededeHfdQZPi fdedefdRZQi fdeded4e3fdSZRddefdTZSi fdedeTfdUZUddVededeTfdWZVi fdeWfdXZXi fded4e3dYedZedeYf
d[ZZdNedefd\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daZ_ddddi fdededededee`         f
dbZaddVedede`fdcZbi fdefddZcddefdeZddi fdfeedefdgZfi fdedegfdhZhdddi fdededefdiZiddedegfdjZji fdefdkZkdi fdedeel         fdlZmddmedefdnZndddi fdededefdoZoddefdpZpddi fd$eded2e5d3e6d4e7d5e7de/fdqZqdddi fdedededeer         fdrZsddsedederfdtZtdu Zuddddi fdvedededefdwZvdddi fdedededeew         fdxZxddefdyZyddededeew         fdzZzddi fdefd{Z{di fd|e|defd}Z}di fdefd~Z~d Zddi ddfdZdeedededededefdZ xZS )bitmartreturnc                    |                      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ԓddxddxddddddddԓddi ddddddddddddԓddddddԓddddddddddddddddԓddidddddxd~ddddddddddddddd|                     d          |                     d          |                     d           |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d	          g|                     d
          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg|                     d           |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d
          |                     d          g|                     d          |                     d          g|                     d          |                     d          ggdd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          d0t          d1t          d2t          d3t          d4t          d5t          d6t          d7t          d8t          d9t          d:t          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          dt          dTt"          dUt          dVt          dWt          dXt&          dYt(          dZt(          d[t(          d\t(          i d]t(          d^t(          d_t(          d`t(          dat          dbt          dct          ddt          det          dft          dgt          dht          dit          djt"          dkt          dlt          dmt          i dnt          dot          dpt(          dqt&          drt&          dst&          dtt(          dut(          dvt(          dwt          dxt          dyt          dzt          d{t"          d|t          d}t          d~t"          i dt          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*          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/d0d0d1d1d2d2d3d3d4d4d5d5d6d7d8d9d:d:d;d;d<d<d=d=d>d>d?d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdddddOddPdidddkddQdR
dddd dddd dddddSddddddddTdUdiddVd dWddXdddddYddVddddZd ddVd 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dadddddSdddddbdd d dWdcdddddddedddfddVd d d dddgd\dhididjd_idjdkidjdkidld d dldmdn          S (o  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/v4/algo/submit_orderzspot/v4/algo/cancel_orderzspot/v4/algo/cancel_all   zspot/v4/query/algo/orderg      ?zspot/v4/query/algo/client-orderzspot/v4/query/algo/open-ordersz!spot/v4/query/algo/history-orderszspot/v3/cancel_orderzspot/v2/batch_orderszspot/v2/submit_orderzspot/v1/margin/submit_orderz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-ordersz"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 enoughz.This trading pair does not support API trading)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 )r1  limitdaysBack	untilDayssymbolRequired)r1  triggerr:  rE  )r1  rB  rF  r:  rE  )r1  rB  rC  daysBackCanceledrD  rF  r:  rE  rB    )	sandboxrW   rX   r{   r   r   r   rd   r|   default)lastmarkindex)r3  price)r1  r2  r3  r4  r5  r6  r7  r8  r9  r:  r;  r<  )r1  rB  rC  rD  )r1  rF  r:  d   )r1  rB  rF  r:  )r1  rB  rC  rG  rD  rF  r:    )extendsrW   r{   r   r   rd   r|   rQ  forDerivatives)linearinverse)rJ  rR  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    J/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/bitmart.pyrY  zbitmart.describe#   s"   gt 4 4 = = ? ? SB
)SB
ISB
 111SB
 SB
 tSB
 SB
 4S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( ()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 V 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 V 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 V 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 VSB
B CSB
D i:=  2;= #  9 ESB
` "$ $aS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. )!/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 1T @C35:<AC@B@B>?a1 1 1d;A2; A"; B2	;
 @; A"; KC; KC; J3; 4S; /; /; /;  0!;" .q#;$ 5a%;& 4Q';( 7); ;* /+;, 5a-;. 0/;0 -b1;2 /3;4 4Q5;6 4Q7;8 229;: 3C;;< :3=;> 9!?;@ <QA;D /E;F /G;H /I;L 6sM;N 9"O; ; ;P 8Q;R ;BS;V <RW;X 7Y;Z 8[;\ 8];^ 9"_;` =ca;b =cc;d ;Ce;f >sg;h =ci;j DSk;l >sm;n >so;p >sq;r >ss; ;t =au; ;go oER RkSB
P  QSB
n !%"&!..x88!..x88 "..s33T5F5Fx5P5PQ!..t44d6G6G6O6OP!..t44d6G6G6Q6QR!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I(8S8ST!..w779J9J89T9TU!..w779J9J89T9TU	" "..s33T5F5Fw5O5OP!..t44d6G6G6Q6QR!..t44d6G6G6Q6QR!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I(8S8ST!..w779J9J89T9TU!..w779J9J89T9TU	"  oSB
j	 Yk	SB
l	 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& -'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 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 J 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 J 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 J 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 J 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 J 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\ ]]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 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 J 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 JD *))--)))SJ J JX J[FO YP Pm	SB
N "$(!! 	! 	!OSB
f $ "$ $
 #$+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 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 V 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 V 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 V 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 VJ % ""("" ""  !eV V Vp # '"$	! !  &F! #"# # 6:-]o od  %&*(-,0,1).+06:#'#("&#(	( ( #($)27+/$(/4#()$ $. r% '+!$$(%**/& & ',#($)*/	# # '+!$#($)*/( ( $(&*!$$(,0%)#($)*/	* 	*  #u= =~  )&*(,$($(%*- -
 -1)-+/ )-(,).1 1
 &+7 7 $(#'"&#(	( ( #($(26+/9"$ "$H '+!%$(%*	& & ',#($(# # ',!$#'$)	( ( '+!$$(,0%)#($)* *  #B# B#H y
 "#3 "#3 	  ## [Q QCSB
 SB
 SB
 S S S	    c                     |                      |          }|                     |di           }|                     |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)r[  paramsresponser`  s       r]  
fetch_timezbitmart.fetch_timey  sD     ++F33 ~~h33  }555r^  c                 p   |                      | j        di           }|                     | j        d          }|                     |d|          }|                     |d|          }|                     |d          }|                     |          }|                      |di           }|                     |dg           }|                     |d          }|dk    rd}|                      ||          }	d	}
d	}|	7|                     |	d
          }|dk    rd}
nd}
|                     |	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)rl  updatedetar   info)rc  rU  safe_stringomitpublicGetSystemService	safe_listindex_byrd  )r[  re  rU  r)  r"  rf  r`  servicesservicesByTyperi  rl  rr  
statusCodes                r]  fetch_statuszbitmart.fetch_status  sS    ..}bAA&&t|]CC==5566**..v664 ~~h33>>$	266x@@6>>D..66**7H==JQ&''<<
 
 	
r^  c                    |                      |          }|                     |di           }|                     |dg           }g }| j        d         }t	          dt          |                    D ]}||         }|                     |d          }	|                     |d          }
|                     |d          }|                     |d          }|                     |          }|                     |          }|d	z   |z   }|                     |d
          }|                     |d          }t          j
        ||          }|                     |d          }|                    |                     i d|	d|
d|d|d|dd d|d|dd ddddddddddddd|                     |dd          dk    d dd d d d d d d |d!         |d"         ||                     |                     |                     |d#                              d$d d d%||                     |d&          d%d d d%|                     |          d d%d'd |d(                     |S ))Nr`  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   activerl  trade_statusrk  r   r   price_max_precisionamountrN  minr@  base_max_sizer=  r  rN  costrS  rT  contractSizeexpiryexpiryDatetimestrike
optionTyper   r   	precisionlimitscreatedrs  )publicGetSpotV1SymbolsDetailsrc  rw  r   rangelenrt  rd  safe_currency_coder6   
string_maxsafe_numberappendsafe_market_structuresafe_string_lower_2rZ  parse_precision)r[  re  rf  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3..y"55y#q#g,,'' @	 @	AQZF!!&(33B))&+>>I%%fo>>F&&v/?@@G**622D++G44ECZ%'F))&2BCCJ**63DEEK([AAG**6?CCKMM$44 36b36Y36 &36 	36
 36 $36 &36 736 D36 36 36 %36 36 %36 %36  $2268^TTXaa!36" E#36$  $"&"gg)!..t/C/CDDTDTU[]rDsDs/t/tuu   $#! !
  +#//HH 
  $# 
  $0099#  $  e36 36 36 3 3 3 3 3 3h r^  c                 X   |                      |          }|                     |di           }|                     |dg           }g }| j        d         }t	          dt          |                    D ]8}||         }|                     |d          }	|                     |d          }
|                     |d          }|                     |
          }|                     |          }d}|                     |          }|d	z   |z   d
z   |z   }|                     |d          }|dk    }|dk    }|                     |d          }|s|dk    rd }|	                    | 
                    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k    d d!d!d|                     |d"          ||                     |          d d |d#         |d$         |                     |d%          |                     |d&          d'|                     |d(          |                     |d)          d*|                     |d+          |                     |d,          d*d d d*d d d*d-|                     |d.          |d/                     :|S )0Nr`  r~  r   r   r  r  r  r  r  :product_typer   rm  expire_timestampr;   r  r  r  r  r  r  r  r"  rL   rM   rJ   FrK   rN   r  rl  rk  Tcontract_sizer   r   vol_precisionprice_precisionr  min_leveragemax_leverager  
min_volume
max_volumer  open_timestampr  )publicGetContractPublicDetailsrc  rw  r   r  r  rt  r  rd  r  r  safe_string_lowerr  iso8601)r[  re  rf  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_markets2  s   66v>>P ~~h33..y"55y#q#g,,'' C	 C	AQZF!!&(33B%%fo>>F&&v/?@@G**622D++G44EH,,X66FCZ%'#-6F++FNCCK!Q&F$)I&&v/ABBF &A++MM$44 36b36T36 &36 	36
 36 &36 &36 736 H36 &6h36 36 %36 36 )36 %36  $00BBiO!36" D#36$   $ 0 0 I I "&,,v"6"6"gg"..vGG!--f6GHH   $//GG#//GG! !
  $//EE#//EE 
  $# 
  $#  $  ,,V5EFFe36 36 36 3 3 3 3 3 3h r^  c                     | j         d         r|                                  |                     |          }|                     |          }||g\  }}|                     ||          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&  )rU  load_time_differencer  r  array_concat)r[  re  spotPromisecontractPromiserJ   rk  s         r]  fetch_marketszbitmart.fetch_markets  sp     <12 	(%%'''--f5555f==%7h  x000r^  c                    |                      |          }|                     |di           }|                     |dg           }i }t          dt	          |                    D ]}||         }|                     |d          }|}	|                     |d          }
|                    d          dk    }|sW|                    d          }|                     |d          }	|                     |d          }||                                }
| 	                    |	          }|                     ||          }|%||	|d	|                     |d
          d	d	d	i |rdndd
}| 
                    |
          }|                     |d          }|                     |d          }||
||||o||                     |d          |                     |d          d	dd	d	ddd|d         |<   |||<   t          |                                          }t          dt	          |                    D ]*}||         }||         }|                     |          ||<   +|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)
rs  r;   coder  r<   depositr   r  r'  r"  withdraw_enableddeposit_enabledwithdraw_feewithdraw_minsizer  )r   r  )rs  r;   r  r   r  r  feer  r'  )publicGetAccountV1Currenciesrc  rw  r  r  rt  findsplitupperr  network_id_to_code	safe_boolr  listkeyssafe_currency_structure)r[  re  rf  r`  r  r  r  r  fullId
currencyId	networkIdisNtfpartssecondcurrencyCodeentrynetworkCoder   r  r  keys                        r]  fetch_currencieszbitmart.fetch_currencies  s    44V<<2 ~~h33^^D,;;
q#j//** 1	) 1	)A!!}H%%h
;;FJ((9==I[[''1,E /S))!--eQ77
))%33% &I22:>>LNN6<88E}$$(!% ,,Xv>># $" "',:GG(  11)<<K~~h0BCCHnnX/@AAG #$"".w''.AA  $//:LMM#! !
  $#   	 	. .E*k*& $)F<  FKKMM""q#d))$$ 	A 	AAq'Cc{H66x@@F3KKr^  r  r  c                    ||                      |          }|                     |          }|d         }d }|                     |di           }i }||                     ||          }|Rt          |                                          }	t          |	          }
|
dk    r|                     ||	d                   }|                     |di           }|                     |d          }nb|                     ||          }|.|                     |di           }|                     |d          }n|d|                     ||          z   z  }||n|S )Nr;   r'  r   rs  r  r  )	default_network_coder  rc  r  r  r  
safe_valuert  network_code_to_id)r[  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  sS   33LAAK==..d^!>>(J;;nnX|<<GHMMOO,,TA::"oohQ@@G..&"==K ,,[*EEMM'+~~h'L'L$'3"nn-EvrRR $ 0 0j I IcD33KNNNN!.!:}}Cr^  r  c                 h   |                                   |                     |          }d}|                     |          \  }}d|                     |d         |          i}|                     |                     ||                    }|d         }i }|                     |d          ||<   ||i dS )af  
 @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  )rs  r   r  )load_marketsr  handle_network_code_and_paramsr  !privateGetAccountV1WithdrawChargeextendr  )	r[  r  re  r  r  requestrf  r`  withdrawFeess	            r]  fetch_transaction_feezbitmart.fetch_transaction_fee0  s     	==&&==fEEBB8FCSU\]]
 99$++gv:V:VWW !--dNCCT$
 
 	
r^  Nr  c                 D    ||                      |d          d dd d di dS )Nr  )r  r   )rs  r   r  r'  )r  )r[  r  r  s      r]  parse_deposit_withdraw_feez"bitmart.parse_deposit_withdraw_feeW  sM     ''^<<" 
 "  
 
 	
r^  c                    |                                   d}|                     |          \  }}d|                     ||          i}|                     |                     ||                    }|d         }|                     |          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  )r[  r  re  r  r  rf  r`  s          r]  fetch_deposit_withdraw_feez"bitmart.fetch_deposit_withdraw_feem  s     	==fEEBB4QQ
 99$++gv:V:VWW ..t444r^  tickerr  c           	         |                      |dg           }|                     |dd          }|                     |dd          }|                     |dd          }|                     |dd	          }|                     |d
d          }|                     |d          }	|                     |dd          }
|                     |dd          }|                     |dd          }|                     |dd          }|                     |dd          }|                     |dd          }|                     |d          }|                     |g d          }|                     |g d          }|                     |d          }|
|}|                     |d          }|                     |d          }
|                     |d          }|                     |d           }|                     |d!          }|                     |d"          }|                     |d#          }|                     |d$          }|                     |d%          }|                     |d&          }	|                     |d'          }|                     |d(          }|                     ||          }|d         }|| 	                    |d)d*          }|t          j        |	d+          }|||                     |d,|          }n|}d }|                     i d|d|d-|                     |          d.|
d/|d0|d1|d2|d3|d4d d5|d6|d	|d7d d8d d9|d:||||                     |d          |d;|          S )<Nr  	avg_priceindex_pricer  contract_symbol	timestampts
last_pricerK  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   r   rm  r   s_trH  100r  datetimehighlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechanger   average)
baseVolumequoteVolume
indexPricers  )rw  safe_string_2safe_integer_2rt  safe_string_nsafe_string_lower_nrd  r  safe_marketsafe_integer_productr6   
string_mulsafe_tickerr  )r[  r  r  r  r3  marketIdr	  rK  r   r2  r(  r)  r*  r+  r,  r-  r/  r4  r5  listMarketIdr  s                        r]  parse_tickerzbitmart.parse_ticker  s?   h "55$$V[-HH%%fh8IJJ''TBB	!!&,??''0JLYY
!!&-88!!&*lCC  K@@  X>>&&vII	  X>>&&vII	
33''0Z0Z0Z[[
..v7e7e7eff''22##H))&"55I##FA..D""61--C""61--C((33I""62..C((44I##FA..D##FA..D%%fa00F))&!44J00;;K!!(F33!11&%FFI +FE::J!"..v|[QQ )!
 !
f!
!
 Y//!
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  *!!
" w#!
$ %&**6=AA+!
 !
 !
, -  	r^  r  c                    |                                   |                     |          }i }d}|d         r5|d         |d<   |                     |                     ||                    }n`|d         r5|d         |d<   |                     |                     ||                    }n#t          | j        dz   |d         z   dz             g }i }|d         r|                     |d	i           }nE|                     |d	i           }|                     |d
g           }|                     |di           }| 	                    ||          S )a0  
        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;   rc  rw  rA  )	r[  r  re  r  r  rf  tickersr  r`  s	            r]  fetch_tickerzbitmart.fetch_ticker*  sm    	V$$&> D	T &tGH::4;;wPV;W;WXXHHP F^ 	T &tGH::4;;wPV;W;WXXHH0 tw)KKfU[n\  `S   S  T  T  T&> 	4^^Hfb99FF>>(FB77DnnT9b99G^^GQ33F  000r^  r~  c                 B   |                                   |                     |          }d}d}|+|                     |d          }|                     |          }|                     d||          \  }}d}|dk    r|                     |          }n9|dk    r|                     |          }nt          | j        dz   |z   dz             g }|dk    r| 	                    |dg           }n.| 
                    |di           }| 	                    |d	g           }i }	t          dt          |                    D ]P}
i }|dk    r|                     d
||
         i          }n|                     ||
                   }|d         }||	|<   Q|                     |	d|          S )al  
        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 rC  r`  r~  r  r  )r  market_symbolsrt  r  handle_market_type_and_paramspublicGetSpotQuotationV3Tickersr  r.   r;   rw  rc  r  r  rA  filter_by_array_tickers)r[  r~  re  r"  r  r  rf  rE  r`  r  r  r  s               r]  fetch_tickerszbitmart.fetch_tickers  s    	%%g..%%gq11F[[((F99.&RXYYf6>>;;FCCHH2 V^^::6BBHHR tw)LLtS  WJ   J  K  K  K6>>nnXvr::GG>>(FB77DnnT9b99Gq#g,,'' 	$ 	$AFv~~**Hgaj+ABB**71:66H%F#F6NN++FHgFFFr^  rB  c                    |                                   |                     |          }d|d         i}d}|d         r1|||d<   |                     |                     ||                    }nU|d         r*|                     |                     ||                    }n#t          | j        dz   |d         z   d	z             |                     |d
i           }|                     |dd          }| 	                    ||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   rB  rL   z# fetchOrderBook() does not support r"  rC  r`  r
  r	  )
r  r  publicGetSpotQuotationV3Booksr  publicGetContractPublicDepthr.   r;   rc  r8  parse_order_book)	r[  r  rB  re  r  r  rf  r`  r	  s	            r]  fetch_order_bookzbitmart.fetch_order_book  s2    	V$$fTl
 &> 	W #( 99$++gv:V:VWWHHF^ 	W88Wf9U9UVVHHtw)NNQWX^Q__  cV   V  W  W  W\ ~~h33''dK@@	$$T6(+;YGGGr^  tradec                 $   |                      |g d          }|                     |d          }|d u}d }d }d }d }	|rE|                     |dd          }|                     |d          }|                     |dd          }	nm|                     |g d          }|                     |d	          }|                     |d          }|                     |                     |d
                    }	|                     |dd          }
|                     |
|          }|                     |dd          }d }|H|                     |d          }|                     |          }||	dk    r|d         n|d         }||d}|                     ||                     |g d          |                     |dd          ||                     |          |d         ||	|                     |g d          ||| 	                    |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)rN  	fillPricerm  	tradeRole	exec_type)rs  r;   orderr	  r'  r  r"  r[  rN  r  r  takerOrMakerr  )
safe_integer_nrt  r7  r9  parse_order_sider;  r  
safe_trader  r  )r[  rR  r  r	  isPublicisPublicTrader  r  r"  r[  r?  feeCostStringr  feeCurrencyIdfeeCurrencyCodes                  r]  parse_tradezbitmart.parse_trade>  sd   r ''/O/O/OPP	##E1--!- 	J''w::F##E844D%%eVQ77DD''/I/I/IJJF##E:66D##E622D(()9)9%)H)HIID%%eXq99!!(F33**5%EE$ ,,UMBBM"55mDDO&59U]]&..PW%+ C $$U,R,R,RSS''y*EE"Y//X&''/H/H/HII 44UKUU 
  
   	r^  sincec                 |   |                                   |                     |          }|d         s#t          | j        dz   |d         z   dz             d|d         i}|||d<   |                     |                     ||                    }|                     |d	g           }|                     ||||          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;   NrB  r`  )r  r  r.   r;   publicGetSpotQuotationV3Tradesr  rw  parse_trades)	r[  r  rs  rB  re  r  r  rf  r`  s	            r]  fetch_tradeszbitmart.fetch_trades  s     	V$$f~ 	Itw)KKfU[n\  `H   H  I  I  IfTl
 $GG66t{{7F7S7STT" ~~h33  vue<<<r^  c           
      8   t          |t                    r|                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS |                     |dd          |                     |d	d
          |                     |dd          |                     |dd          |                     |dd          |                     |dd          gS )Nr   r   rm  r   r   r   r	  r
  
open_priceor  hr  lclose_pricecvolumev)
isinstancer  safe_timestampr  safe_timestamp_2safe_number_2)r[  ohlcvr  s      r]  parse_ohlcvzbitmart.parse_ohlcv  s   V eT"" 	##E1--  **  **  **  **  **  %%e[$??""5,<<""5,<<""5+s;;""5-==""5(C88 r^  r   	timeframec           	      6   |                                   d}|                     |ddd          \  }}|r|                     d|||||d          S |                     |          }|                     |          }|                     | j        |          }	d|d         i}
|	|	|
d<   n||
d<   |d	         rC|                     d
|
|d          \  }
}|||
d<   ||                     |dz            dz
  |
d<   nd}||}t          ||          }|                     | 
                                dz            }||||z  z
  }||
d<   ||
d<   nL|                     |dz            dz
  }|                     |||z            }||
d<   t          ||          |
d<   |                     d|
|d          \  }
}d}|d         r|                     |d          }|dk    r@|                     |d          }|                     |                     |
|                    }nS|                     |                     |
|                    }n)|                     |                     |
|                    }|                     |dg           }|                     |||||          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|   paginaterA  r  r;   NsteprJ   beforegMbP?rB  rH  r   afterrP  
start_timerp  rL   rN  rL  r`  )r  handle_option_and_params"fetch_paginated_call_deterministicr  parse_timeframerd  r   handle_until_optionparse_to_intr  millisecondssumrt  ru  %publicGetContractPublicMarkpriceKliner  publicGetContractPublicKlinepublicGetSpotQuotationV3Klinesrw  parse_ohlcvs)r[  r  r  rs  rB  re  r  r  durationparsedTimeframer  maxLimitnowstartendrf  rN  r  s                     r]  fetch_ohlcvzbitmart.fetch_ohlcv  s     	88z[`aa& 	w::<QVX]_hjpruvvvV$$''	22++DOYGGfTl
 &-GFOO'GFO&> 	["66x&RWXXOGV #(  #'#4#4edl#D#Dq#H H} %((E##D$5$5$7$7$$>??C}eh..(-%&)
##))54<99A=hhueh&677(-%&)#smm
#"66z7FTYZZOGV&> 	Y$$VW55E6733EEdkkRY[aFbFbcc<<T[[RX=Y=YZZ::4;;wPV;W;WXXHD x44  	5%HHHr^  c                    |                                   d}i }| |                     |          }|d         |d<   d}d}|                     d||          \  }}|                     |g d          }	|                     |dg          }|dk    rd}
|                     d|          \  }
}|
dk    rd	|d
<   |                     | j        di           }d}|                     |d|          }||}t          ||          |d<   |||d<   |	|	|d<   | 
                    |                     ||                    }nt|dk    rQ|t          | j        dz             |||d<   |	|	|d<   |                     |                     ||                    }nt          | j        dz   |z   dz             |                     |dg           }|                     ||||          S )a  

        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)
        :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nr;   r  r{   )untilendTimerp  r  rJ   isolated
iso_margin	orderModerA  rB  	startTimer  rL   z+ fetchMyTrades() requires a symbol argumentr  rp  z" fetchMyTrades() does not support / orders, only spot and swap orders are acceptedr`  )r  r  rI  rj  ru  handle_margin_mode_and_paramsrc  rU  rd  r  privatePostSpotV4QueryTradesr  r'   r;   privateGetContractPrivateTradesr.   rw  rw  )r[  r  rs  rB  re  r  r  r"  rf  r  r1  rU  r  defaultLimitr`  s                  r]  fetch_my_tradeszbitmart.fetch_my_tradesn  s:     	[[((F &tGH99/6SYZZf##F,L,L,LMM6G9--6>>J!%!C!COU[!\!\JZ'''3$nnT\?BGGGH,,WgxHHL}$"5(33GG ',$ %*	"88Wf9U9UVVHHV^^~'2_(_``` (-% &+
#;;DKKQW<X<XYYHHtw)MMPTT  XI   I  J  J  Jh ~~h33  vue<<<r^  r;   c                     |                                   d|i}|                     |                     ||                    }|                     |dg           }|                     |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
        :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        rc  r`  N)r  !privatePostSpotV4QueryOrderTradesr  rw  rw  )	r[  r;   r  rs  rB  re  r  rf  r`  s	            r]  fetch_order_tradeszbitmart.fetch_order_trades  st     	r
 99$++gv:V:VWW~~h33  tUE:::r^  c                    |                      |di           }d }|dk    r|                     |dg           }n5|dk    r|                     |dg           }n|                     |dg           }d|i}|dk    r#t          dt          |                    D ]}||         }|                     |d          }|                     |d d	          }	|                      |d
i           }
|                      |di           }|                     |                     |
d                    }|                     |                     |d                    }i }|                     |
          ||<   |                     |          ||<   |                     |          ||	<   |S t          dt          |                    D ]}||         }| 	                    |dd          }|                     |d|          }|                     |          }| 
                                }| 	                    |dd          |d<   |                     |g d          |d<   |||<   |                     |          S )Nr`  rL   rK   r~  walletrs  r   r  _r  r  r  r;   	coin_code	availableavailable_balancefree)unAvailablefrozenfrozen_balanceused)rc  rw  r  r  rt  safe_symbolr  parse_balance_helpersafe_balancer7  accountr9  )r[  rf  
marketTyper`  r  r  r  r  r?  r  r  r  baseCode	quoteCode	subResultbalancer  r  r  s                      r]  custom_parse_balancezbitmart.custom_parse_balance  sr   ~~h33^^Hfb99FF8##^^D)R88FF^^D(B77F(#!!1c&kk** > >q	++E8<<))(D#>>~~eVR88ugr::2243C3CD*3U3UVV 33D4D4DUJ4W4WXX	"$	&*&?&?&E&E	(#'+'@'@'G'G	)$!%!2!29!=!=vM1c&kk** ' ' )!//zJJ
!--g{JOO
..z::,,.."&"4"4WkK^"_"_"&"4"4W>i>i>i"j"j&t$$V,,,r^  c                 L   |                                  }|                     |d          |d<   |                     |d          |d<   |                     |d          |d<   |                     |d          }|                     |d          }t          j        ||          |d	<   |S )
Nr  r  r  r  total_assettotalborrow_unpaidinterest_unpaiddebt)r  rt  r6   
string_add)r[  r  r  r  interests        r]  r  zbitmart.parse_balance_helper	  s    ,,..**5(;;**5+>>++E=AA77##E+<==!,T8<<r^  c                 B   |                                   d}|                     dd|          \  }}|                     |d          }|                     |dd          }|                     |ddg          }||rd}d}|dk    r|                     |          }nq|dk    r|                     |          }nU|dk    r|                     |          }n9|dk    r|                     |          }nt          | j
        d	z   |z   d
z             |                     ||          S )an  
        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_   r1  rK   FrJ   rL   r  z! fetchBalance() does not support zE markets, only spot, swap and account and margin markets are accepted)r  rI  rt  r  ru  privateGetSpotV1Wallet%privateGetContractPrivateAssetsDetailprivateGetAccountV1Wallet%privateGetSpotV1MarginIsolatedAccountr.   r;   r  )r[  re  r  r1  isMarginrf  s         r]  fetch_balancezbitmart.fetch_balance	  sZ    	
!??PTV\]]
F%%fl;;
>>&(E::6Hl#;<<!X!!J226::HH6!!AA&IIHH9$$55f==HH8##AA&IIHHtw)LLzY  ]d   d  e  e  e~ ((:>>>r^  r  c                     |                      |d          }|                     |          }|||                     |d          |                     |d          d d dS )Nr  maker_fee_ratetaker_fee_rate)rs  r  r   r   r   r   )rt  r  r  )r[  r  r  r?  r  s        r]  parse_trading_feezbitmart.parse_trading_fee	  so     ##C22!!(++%%c+;<<%%c+;<<
 
 	
r^  c                 h   |                                   |                     |          }|d         s#t          | j        dz   |d         z   dz             d|d         i}|                     |                     ||                    }|                     |di           }|                     |          S )ac  
        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"  ru  r  r;   r`  )r  r  r.   r;   privateGetSpotV1TradeFeer  rc  r  r[  r  re  r  r  rf  r`  s          r]  fetch_trading_feezbitmart.fetch_trading_fee	  s     	V$$f~ 	Mtw)OORXY_R``  dL   L  M  M  MfTl
 00Wf1M1MNN ~~h33%%d+++r^  rh  c                    d }t          |t                    r|}i }|                     |dd|          }|                     |dd          }|                     |d          }|                     ||          }|                     ||          }|                     |dd          }|                     |d          }d }	d }
|dk    rd	}d
}
d}	|dk    rd	}d}	|                     |d          }|dk    r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"|                     |g d#          d$|                     |g d%          d |                     ||                     |d&d'                    d d d(|          S ))Nrd  rc  rU  rT  r  r"  rJ   limit_makerrB  Tr/  iocr-  rN  zmarket priceactivation_pricer;   clientOrderIdclient_order_idrs  r	  r'  lastTradeTimestampupdate_timer8  postOnlyr[  r2  r  rW  r  filled_notionalfilledNotionalr3  )	price_avgpriceAvgdeal_avg_pricefilled)filled_size
filledSize	deal_sizerl  state)	remainingrl  r  trades)r  strr7  r8  rt  r  r;  r  
safe_orderr  rd  rk  	omit_zeror9  parse_order_status_by_type)r[  rh  r  r;   r	  r?  r  	orderTyper"  r8  r  priceStringtrailingActivationPrices                r]  parse_orderzbitmart.parse_order	  s   X eS!! 	BEz9bAA''}lKK	##E844!!(F33!!&&11$$VVV<<	v..=  DHK5==DK&&ug66.((K"&"2"25:L"M"M  
" 
T//7H/ZZ 
 E 
 	 

 Y// 
 !$"3"3E="I"I 
 f 
 D 
 ; 
  
 D))$*:*:5&*I*IJJ 
 T^^K00 
 3 
 dnnT%5%5eV%D%DEE 
 D&&u.?AQRR 
  t))%1\1\1\]]! 
" d((0Z0Z0Z[[# 
$ 55iASASTY[celAmAmnn+ 
  
  
, -  	r^  c                 >    ddddd}|                      |||          S )Nr^  sell)1234rt  )r[  r[  sidess      r]  rk  zbitmart.parse_order_sideL
  s4    	
 
 tT222r^  c                     dddddddddddddddddd}|                      ||i           }|                     |||          S )Nrejectedr/  closedcanceled)r  r  r  r  5678newpartially_filledr  partially_canceled)r  r  r  r   )rc  rt  )r[  r"  rl  statusesByTypestatusess        r]  r  z"bitmart.parse_order_status_by_typeU
  s      $*"&0    
  
* >>.$;;&&999r^  r  c                     |                                   |                     |          }|d         st          | j        dz             d|d<   |                     |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  r^  N)r  r  r.   r;   create_order)r[  r  r  re  r  s        r]  !create_market_buy_order_with_costz)bitmart.create_market_buy_order_with_costn
  ss     	V$$f~ 	ftw)ddeee6;23  5$fMMMr^  r"  r[  r  rN  c                    |                                   |                     |          }|                     d|          }|                     |d          }	|                     |g d          }
|                     |d          }|                     |d          }|du}|du}|
du}d}|d         rh|                     ||||||          }|s|s|r|                     |          }n|	dk    r|                     |          }n|                     |          }n| 	                    ||||||          }|                     |d	          }|| 
                    |          }nG|r|                     |          }n/|s|r|                     |          }n|                     |          }|                     |d
i           }|                     ||          }||d<   ||d<   ||d<   ||d<   |S )am
  
        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
        https://developer-pro.bitmart.com/en/spot/#new-algo-order-v4-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
        :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        rW   r   r2  	stopPricetrigger_pricer5  r6  NrJ   r  r  r`  r"  r[  r  rN  )r  r  r  rt  r9  create_spot_order_request privatePostSpotV4AlgoSubmitOrder"privatePostSpotV1MarginSubmitOrderprivatePostSpotV2SubmitOrdercreate_swap_order_request*privatePostContractPrivateSubmitTrailOrder)privatePostContractPrivateSubmitPlanOrder)privatePostContractPrivateSubmitTpSlOrder%privatePostContractPrivateSubmitOrderrc  r  )r[  r  r"  r[  r  rN  re  r  r  r1  r2  r5  r6  
isStopLossisTakeProfitisTriggerOrderrf  spotRequestswapRequestactivationPricer`  rh  s                         r]  r  zbitmart.create_order
  sG   F 	V$$33M6JJ%%fa00
))&2`2`2`aa((AA**63DEE"$.
&d2%T1&> 	S88tVUZ\bccK J\ J^ J@@MMz))BB;OO<<[II88tVUZ\bccK"..{<NOOO*JJ;WW SII+VV S| SII+VVEEkRR  ~~h33  v..ff hgr^  ordersc           	      H   |                                   g }d}d}t          dt          |                    D ],}||         }|                     |d          }|                     |          }|d         st          | j        dz             ||}n||k    rt          | j        dz             |                     |d          }	|                     |d          }
|                     |d	          }|                     |d
          }| 	                    |di           }| 
                    ||	|
|||          }|                     |dg          }|                    |           .|d         |d}|                     |          }| 	                    |di           }| 	                    |di           }|                     |dg           }g }t          dt          |                    D ]7}||         }|                     d|i|          }|                    |           8|S )an  
        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
        :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
        :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"  r[  r  rN  re  r;   )r  orderParamsr`  orderIds)r  r  r  rt  r  r.   r;   r(   r  rc  r  ru  r  privatePostSpotV4BatchOrdersrw  r  )r[  r%  re  ordersRequestsr  r  r  rawOrderr?  r"  r[  r  rN  r'  orderRequestr  rf  r`  
innderDatar(  parsedOrdersrc  rh  s                          r]  create_orderszbitmart.create_orders
  sA    	q#f++&& 	0 	0AayH''(;;H[[**F&> Z"47-X#XYYY~!X%%$TW/l%lmmm##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K99(D$PVX]_jkkL99\H:>>L!!,////Tl)
 
 44W==" ~~h33^^D&"55
>>*j"==q#h--(( 	' 	'AqkGOOT7OV<<E&&&&r^  c                 z   |                      |          }|                     |d          }|                     |d          }	|du}
|	du}|
rd}n|rd}|d         t          |                     ||                    d}|                     |d          }|                     |d	          }|d
k    }d}|                     |d          }|dk    }|                     |||          \  }}|dk    p|dk    }|dk    p|p|}|dk    rd|d	<   n|dk    rd|d	<   n|dk    rd|d	<   |rd|d	<   |                     |g d          }|du}|                     |dd| 	                    |                    }|                     |dd          }|du}|r| 
                    ||          |d<   nB|dk    s|r:d}||d<   | 
                    ||          |d<   |                     |dd          |d<   |rw|s|| 
                    ||          |d<   | 
                    ||          |d<   |                     |dd          |d<   |dk    r|rd|d <   nd|d <   n|d!k    r|rd|d <   nd|d <   d}|                     d"|d#          \  }}|
s|rkd$}|                     |dd          |d<   | 
                    ||          |d<   |
r| 
                    ||          |d<   n| 
                    ||	          |d<   n||d%<   |dk    r|rd|d&<   nd|d&<   n|d!k    r|rd|d&<   nd|d&<   |                     |d'          }||                     |d'          }||d(<   |                     |d)          }|                     |g d*          }|| 	                    |          |d)<   n|rd+|d)<   |dk    r||d,<   |                     ||          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>`
        r5  r6  N	stop_losstake_profitr;   )r  rW  r8  moder  
reduceOnlyr   r-  r   rB  GTCr   r.  rm  r  trailingTriggerPricer  trailingPercentcallback_raterN  r:  activation_price_typeexecutive_pricer  
price_typer^  	price_wayr  rW   crossT	open_typer[  r  r  r=  )
r8  r  r4  r=  r6  r7  r2  r  r5  r6  r  r"  )r  rt  intamount_to_precisionrd  r  handle_post_onlyr9  r7  number_to_stringprice_to_precisionr  ru  r  )r[  r  r"  r[  r  rN  re  r  r5  r6  r  r   r  r8  r3  isMarketOrderr  r4  isExchangeSpecificPor  isLimitOrderr2  r!  r6  r7  isTrailingPercentOrderr1  r  r=  s                                r]  r  z!bitmart.create_swap_order_request  s%   : V$$((AA**63DEE"$.
&d2 	!DD 	! DTl00@@AA
 
 &&v}==  00(^^FL99
 $	00@TV\]]&u$4$!);H;%GFOOE!!GFOOE!!GFO 	 GFO))&2`2`2`aa%T1#11&:PRdfjf{f{  }B  gC  gC   D   D,,V5FXX!0!< 	e#66vuEEGGZ#9D'6GO$*.*A*A&J^*_*_G&'/3/@/@I`bc/d/dG+, 	- Tu0-1-D-DVU-S-S)*'+'>'>v|'T'TGO$$($5$5flA$N$NGL!u}} -+,GK((+,GK(( -+,GK((+,GK(
!??vW^__
F 		. 		.J$($5$5flA$N$NGL!)-)@)@)O)OG%& \+/+B+B6=+Y+Y((+/+B+B6?+[+[((#-GK 5== $"#"#V^^ $"#"#((AA$YYv77F)6G%&$$VZ886  $E  $E  $E  F  F"&"7"7"A"AGJ 	&"%GJ:"GFO{{7F+++r^  c                 p   |                      |          }|                     |g d          }|                     |d          }	|                     |d          }
|	du}|
du}|du}|p|p|}|d         |d}|                     |d          }|dk    rt          | j        d	z             |                     |d
          }|dk    }d}|dk    p|dk    }|                     |||          \  }}|                     |ddg          }|dk    p|dk    }|dk    p|p|}|rn|rd|d<   nd|d<   |rd|d<   nd|d<   |r|                     ||	          |d<   n=|r|                     ||
          |d<   n!|r|                     ||          |d<   n||d<   |r4| 	                    ||          |d<   |                     ||          |d<   n|r|dk    r| 
                    |dd          }|                     |d          }d}|                     |ddd          \  }}|r[||t          | j        dz             |                     |          }|                     |          }t          j        ||          }n||                     |          n|}|                     |t           |d          d         | j                  |d<   n|d!k    r| 	                    ||          |d<   |rd|d<   |rd|d<   |                     |d"          }||                     |d"          }||d#<   |                     ||          S )$a  
 @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
        https://developer-pro.bitmart.com/en/spot/#new-algo-order-v4-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'
        :param str [params.clientOrderId]: client order id of the order
        :param str [params.triggerPrice]: the price to trigger a stop order
        :param str [params.stopLossPrice]: the price to trigger a stop-loss order
        :param str [params.takeProfitPrice]: the price to trigger a take-profit order
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r  r5  r6  Nr;   )r  r[  r8  r.  zE createOrder() only accepts timeInForce parameter values of IOC or POr3  r  r  r   r  r-  r  rB  rF  r"  tp/sltrigger_typer  rW  rN  r^  r  rZ  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  r9  rt  r,   r;   rd  rA  ru  rC  r@  r7  r  rB  r6   r=  decimal_to_precisionr4   r   r  )r[  r  r"  r[  r  rN  re  r  r2  r5  r6  r  r   r!  isAlgoOrderr  r8  r3  rD  r  rE  r  rF  rZ  r+  amountStringr  r  s                               r]  r  z!bitmart.create_spot_order_request  s6   ( V$$))&2`2`2`aa((AA**63DEE"$.
&d2%T1 BLBNTl
 
 &&v}==%tw)ppqqq  00( $ 5E41900@TV\]]&6M:#>??u$8$%-;H; 	# *"+") 3*1''*2' Y+/+B+B6=+Y+Y(( Y+/+B+B6?+[+[(( Y+/+B+B6<+X+X("GFO 	K"66vvFFGFO#66vuEEGG 	Ku}}--ffjII6622481<@<Y<YZ`bo  rU  W[  =\  =\9164 aH,<*47  6w  ,w  x  x  x'+'<'<V'D'D&*&;&;E&B&B#*#5lK#P#PAIAQt44V<<<X`H&*&?&?(TZ[fTghoTprv  sE  'F  'F
##"&":":66"J"J 	,+GFO 	$#GFO((AA$YYv77F)6G%&{{7F+++r^  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|                     |dd          }|||d<   nt          |          |d<   |                     |dd	          }|                     |d
          }|                     |d          }	|                     |g d          }d}
|d         rg|s|r9|rd|d<   n|rd	|d<   | 	                    | 
                    ||                    }
n|                     | 
                    ||                    }
n|r*|                     | 
                    ||                    }
nU|	r*|                     | 
                    ||                    }
n)|                     | 
                    ||                    }
|d         r|                     d|
i          S |                     |
d          }|du r|                     d|i|          S |                     |d          }|9|                     |d          }| t%          | j        dz   |z   dz   |z             n;|                     |d          }|s#t%          | j        dz   |z   dz   |z   dz             |                     ||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
        https://developer-pro.bitmart.com/en/spot/#cancel-algo-order-v4-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.trailing]: *swap only* whether the order is a stop order
        :param boolean [params.trigger]: whether the order is a trigger order
        :param boolean [params.stopLossTakeProfit]: whether the order is a stopLossPrice or takeProfitPrice order
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr  r;   r  r  rd  stoprF  stopLossTakeProfitr:  )r  rO  rF  r:  rP  rJ   rI  r"  rL   rs  r`  Tsucceedr   z  cancelOrder() failed to cancel z
 order id r  z cancelOrder() z is filled or canceled)r;   r  rs  )r'   r;   r  r  r7  r  safe_bool_2r  ru   privatePostSpotV4AlgoCancelOrderr  privatePostSpotV3CancelOrder)privatePostContractPrivateCancelPlanOrder*privatePostContractPrivateCancelTrailOrder%privatePostContractPrivateCancelOrderr  r  rt  r,   )r[  r;   r  re  r  r  r  rF  rP  r:  rf  r`  	succeededr  rh  s                  r]  cancel_orderzbitmart.cancel_order  s#   ( >#DG.Y$YZZZV$$fTl
 **6?DUVV$)6G%&&"%b''GJ""669==!^^F4HII>>&*556#i#i#ijj&> 	d [, [% 0&-GFOO 0&/GFO@@WV\A]A]^^<<T[[RX=Y=YZZ dII$++V]_eJfJfgg dJJ4;;W^`fKgKghhEEdkkRY[aFbFbcc0 &> 	7??FH#5666x004<<??D":v666OOD)44	 !!)Q//Bz"47-O#ORX#X[g#gjl#lmmm  __T844F x"47->#>#G,#VY[#[^v#vwwwrVH5Er R RTZ[[r^  idsc                    |t          | j        dz             |                                  |                     |          }|d         s#t	          | j        dz   |d         z   dz             |                     |d          }|                     |dg          }d|d	         i}|||d<   n||d
<   |                     |                     ||                    }| 	                    |di           }g }	|                     |dg           }
t          dt          |
                    D ]6}|
|         }|	                    |                     |dd|                     7|                     |dg           }t          dt          |                    D ]6}||         }|	                    |                     |dd|                     7|	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>`
        Nz* cancelOrders() requires a symbol argumentrJ   z! cancelOrders() does not support r"  ru  clientOrderIdsr  r;   r(  r`  
successIdsr   r  )r;   rl  failIdsfailed)r'   r;   r  r  r.   rw  ru  privatePostSpotV4CancelOrdersr  rc  r  r  r  r  )r[  rZ  r  re  r  r\  r  rf  r`  	allOrdersr]  r  r;   r^  s                 r]  cancel_orderszbitmart.cancel_ordersM  s    >#DG.Z$Z[[[V$$f~ 	Jtw)LLvV\~]  aI   I  J  J  J0@AA6$4#566fTl
 %(6G$%%"%GJ55dkk'66R6RSS" ~~h33	^^D,;;
q#j//** 	X 	XAABT__B*-M-MvVVWWWW..y"55q#g,,'' 	V 	VABT__B(-K-KVTTUUUUr^  c                    |                                   i }d}| |                     |          }|d         |d<   d}d}|                     d||          \  }}|dk    r|                     |dd          }|                     |d          }|                     |g d	          }|s|r9|rd
|d<   n|rd|d<   |                     |                     ||                    }nr|                     |                     ||                    }nH|dk    rB|t          | j
        dz             |                     |                     ||                    }|                     d|i          gS )a2  
        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
        https://developer-pro.bitmart.com/en/spot/#cancel-all-algo-order-v4-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'
        :param boolean [params.trigger]: whether the orders are trigger orders
        :param boolean [params.stopLossTakeProfit]: whether the orders are stopLossPrice or takeProfitPrice orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr;   r  rQ   rJ   rO  rF  rP  rO  rF  rP  rI  r"  rL   z- cancelAllOrders() requires a symbol argumentrs  )r  r  rI  rR  r  ru  privatePostSpotV4AlgoCancelAllr  privatePostSpotV4CancelAllr'   r;   &privatePostContractPrivateCancelOrdersr  )	r[  r  re  r  r  rf  r"  rF  rP  s	            r]  cancel_all_orderszbitmart.cancel_all_orders  s    	[[((F &tGH99:KVU[\\f6>>&&vvyAAG!%8L!M!MYYv'P'P'PQQF Y, Y% 0&-GFOO 0&/GFO>>t{{7TZ?[?[\\::4;;wPV;W;WXXV^^~'2a(abbbBB4;;wX^C_C_``H&  23344r^  c                 $   |t          | j        dz             |                                  |                     |          }|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<   |                     |                     ||                    }|                     |di           }	|                     |	dg           }
| 	                    |
|||          S )Nz1 fetchOrdersByStatus() requires a symbol argumentrJ   z( fetchOrdersByStatus() does not support r"  ru  r;   r   rO  )r  offsetNr/  r#  rl  r  r   r  r"  r`  r%  )
r'   r;   r  r  r.   privateGetSpotV3Ordersr  rc  rw  parse_orders)r[  rl  r  rs  rB  re  r  r  rf  r`  r%  s              r]  fetch_orders_by_statuszbitmart.fetch_orders_by_status  sY   >#DG.a$abbbV$$f~ 	Qtw)SSV\]cVdd  hP   P  Q  Q  QTl
 

 V !GHx !GHz!! !GH &GH..t{{7F/K/KLL: ~~h33h33  >>>r^  c                     |                                   d}i }| |                     |          }|d         |d<   d}d}|                     d||          \  }}|                     |dd          }	|                     |d          }
|                     |g d          }|d	k    r|t          |d
          |d<   d}|                     d|          \  }}|dk    rd|d<   |||d<   |                     |dd          }||                     |dg          }||d<   |	s|
r:|	rd|d<   n|
rd|d<   | 	                    | 
                    ||                    }n|                     | 
                    ||                    }n|dk    r|t          |d          |d<   |	r*|                     | 
                    ||                    }n|                     |dd          }|                     |d          }|                     |ddg          }|rd}|||d<   |                     | 
                    ||                    }nt          | j        dz   |z   dz             |                     |dg           }|                     ||||          S )a  
        fetch all unfilled currently open orders

        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
        https://developer-pro.bitmart.com/en/spot/#current-algo-open-orders-v4-signed

        :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]: set to True if you want to fetch trigger orders
        :param boolean [params.stopLossTakeProfit]: set to True if you want to fetch stopLossPrice or takeProfitPrice orders
        :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr;   r  r   rO  rF  rP  rd  rJ   rA  rB  r  r  r  r  r  r  rI  rL   rO  r:  Fr  r"  z$ fetchOpenOrders() does not support r  r`  )r  r  rI  rR  r  ru  r  r  r8  $privatePostSpotV4QueryAlgoOpenOrdersr   privatePostSpotV4QueryOpenOrders)privateGetContractPrivateCurrentPlanOrderrt  &privateGetContractPrivateGetOpenOrdersr.   r;   rw  rm  )r[  r  rs  rB  re  r  r  r"  rf  	isTriggerrP  r1  r  r:  r  r`  s                   r]  fetch_open_orderszbitmart.fetch_open_orders  s   0 	[[((F &tGH99:KVU[\\f$$VVY??	!^^F4HII6#L#L#LMM6>> #&uc?? J!%!C!CDUW]!^!^JZ'''3$ ',$''CCE 6I;77%*	" _. _ 3+4GK((' 3+2GK(DDT[[QXZ`EaEabb@@WV\A]A]^^V^^ #&uc??  
eII$++V]_eJfJfgg>>&*eDD ,,V[AA	6K+DEE + *I(&/GFOFFt{{SZ\bGcGcddtw)OORVV  ZK   K  L  L  Ln ~~h33  vue<<<r^  c                    |                                   d}i }| |                     |          }|d         |d<   d}|                     d||          \  }}|dk    r|t          | j        dz             ||dk    rdnd}|||<   |dk    rd	nd
}	|                     |d|	          }
|
|                     |dg          }|
||	<   |                     |dd          }|                     |d          }|                     |g d          }d}|dk    rd}| 	                    d|          \  }}|dk    rd|d<   |s|r9|rd|d<   n|rd|d<   | 
                    |                     ||                    }nS|                     |                     ||                    }n)|                     |                     ||                    }|                     |dg           }|                     ||||          S )a  
        fetches information on multiple closed orders made by the user

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

        :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
        :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
        :param boolean [params.trigger]: set to True if you want to fetch trigger orders
        :param boolean [params.stopLossTakeProfit]: set to True if you want to fetch stopLossPrice or takeProfitPrice orders
        :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  rp  r  rO  rF  rP  rd  r  r  r  rI  r`  )r  r  rI  r'   r;   r8  ru  rR  r  r  'privatePostSpotV4QueryAlgoHistoryOrdersr  #privatePostSpotV4QueryHistoryOrders%privateGetContractPrivateOrderHistoryrw  rm  )r[  r  rs  rB  re  r  r  r"  startTimeKey
endTimeKeyr  rt  rP  rf  r1  r`  s                   r]  fetch_closed_orderszbitmart.fetch_closed_ordersx  sW   & 	[[((F &tGH99:MvW]^^f6>>~'2c(cddd+/6>>;;L$)GL!#'6>>YY

##FGZ@@YYvy11F"'GJ$$VVY??	!^^F4HII6#L#L#LMM6>>J!%!C!CDWY_!`!`JZ'''3$ b. b 3+4GK((' 3+2GK(GGT[]cHdHdeeCCDKKPWY_D`D`aaAA$++gW]B^B^__H~~h33  vue<<<r^  c                 4    |                      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  )rn  )r[  r  rs  rB  re  s        r]  fetch_canceled_orderszbitmart.fetch_canceled_orders  s      **:vueVTTTr^  c                 H   |                                   i }d}d}d}||                     |          }|                     d||          \  }}|dk    r|                     |d          }|                     |dd          }	|                     |ddg          }|s||d<   |	rW|+|                     |                     ||                    }n(|                     |                     ||                    }n|*| 	                    |                     ||                    }n| 
                    |                     ||                    }n|dk    r|t          | j        d	z             |                     |d
d          }
|                     |d          }|                     |dd
g          }|
rd
}|||d<   |d         |d<   ||d<   |                     |                     ||                    }|                     |di           }|                     ||          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
        https://developer-pro.bitmart.com/en/spot/#query-algo-order-by-id-v4-signed
        https://developer-pro.bitmart.com/en/spot/#query-algo-order-by-clientorderid-v4-signed

        :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
        :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
        :param boolean [params.trigger]: whether the orders is a trigger, stopLossPrice or takeProfitPrice order
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   rJ   r  rO  rF  rc  rL   z( fetchOrder() requires a symbol argumentr:  Fr  r"  r;   r  rd  r`  )r  r  rI  rt  rR  ru  %privatePostSpotV4QueryAlgoClientOrderr  privatePostSpotV4QueryAlgoOrder!privatePostSpotV4QueryClientOrderprivatePostSpotV4QueryOrderr'   r;   r  privateGetContractPrivateOrderrc  r  )r[  r;   r  re  r  r"  r  rf  r  rF  r:  r  r`  s                r]  fetch_orderzbitmart.fetch_order  sN   ( 	[[((F99,PVWWf6>> ,,V_EEM&&vvyAAGYYv	':;;F  (%'	" 	^ ,#II$++V]_eJfJfggHH#CCDKKPWY_D`D`aaHH ,#EEdkkRY[aFbFbccHH#??GU[@\@\]]HHV^^~'2\(\]]]~~fj%@@H((==IYYvZ'@AAF '&	$"+ &tGH"$GJ::4;;wPV;W;WXXHf ~~h33f---r^  c                 d   |                                   |                     |          }d}|                     |          \  }}d|                     ||          i}|                     |                     ||                    }|                     |di           }|                     ||          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  rc  parse_deposit_address)r[  r  re  r  r  r  rf  r`  s           r]  fetch_deposit_addresszbitmart.fetch_deposit_address-  s     	==&&==fEEBB4QQ
 99$++gv:V:VWW ~~h33))$999r^  c           	      "   |                      |d          }|                     |dd          }|                    d          dk     rE|                    d          }|                      |d          }|                      |d          }||}|                      |d          }|                     ||          }|                     |           ||                      |d	          |                     |          ||                     |d
d          dS )Nr  chainr  r  r   r  r   addressr  address_memomemo)rs  r  r  r  tag)rt  r7  r  r  safe_currencycheck_addressr  )r[  depositAddressr  r  r  r  
secondPartr  s           r]  r  zbitmart.parse_deposit_addressO  s   * %%njAA
$$^WiHH??5!!A%%$$S))E))%33J))%33J%$"">9==%%j(;;7###"((6::..w77%%nnfMM
 
 	
r^  r  r  c                    |                      ||          \  }}|                     |           |                                  |                     |          }d}|                     |          \  }}|                     ||          |d|d}|||d<   |                     |                     ||                    }	|                     |	di           }
| 	                    |
|          }|                     ||||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  rc  parse_transaction)r[  r  r  r  r  re  r  r  r  rf  r`  transactions               r]  r   zbitmart.withdraww  s!    99#vFFV7###==&&==fEEBB4QQ/	
 
 ?&)GN#99$++gv:V:VWW ~~h33,,T8<<{{;)
 )
   	r^  c                    |                                   |d}||d}d }| |                     |          }|d         |d<   |||d<   |                     |d          }||                     |d          }||d<   |                     |                     ||                    }	|                     |	di           }
|                     |
d	g           }|                     ||||          S )
NrH  )operation_typerk  r;   r  r  r  r  r`  records)	r  r  rd  ru  )privateGetAccountV2DepositWithdrawHistoryr  rc  rw  parse_transactions)r[  r"  r  rs  rB  re  r  r  r  rf  r`  r  s               r]  fetch_transactions_by_typez"bitmart.fetch_transactions_by_type  s   =E"
 
 }}T**H"*4.GJ#(GK !!&'22YYvw//F!&GIAA$++gW]B^B^__2 ~~h33..y"55&&w%GGGr^  c                 
   |                                   d|i}|                     |                     ||                    }|                     |di           }|                     |di           }|                     |          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  rc  r  r[  r;   r  re  r  rf  r`  r  s           r]  fetch_depositzbitmart.fetch_deposit       	"
 @@WV\A]A]^^. ~~h33h33%%f---r^  c                 4    |                      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  r[  r  rs  rB  re  s        r]  fetch_depositszbitmart.fetch_deposits  s      ..y$ufUUUr^  c                 
   |                                   d|i}|                     |                     ||                    }|                     |di           }|                     |di           }|                     |          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                 4    |                      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_withdrawals7  s      ..z4vVVVr^  rl  c                 B    ddddddd}|                      |||          S )Npendingrn  r  r_  )r   r  r  r  r  r  r   r[  rl  r  s      r]  parse_transaction_statusz bitmart.parse_transaction_statusE  s:    
 
 &&999r^  r  c                    d }|                      |d          }|                      |d          }d }||dk    rd}|}n|
|dk    rd}|}|                     |d          }|                     |d          }|                      |d          }	d }
|	Z|	                    d	          d
k     rA|	                    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
k    r|nd |d
k    r|                     |          nd |d!S )"Nwithdraw_id
deposit_id r   r  arrival_amount
apply_timer  r  r   r  r   rl  r  r_  tx_idr  r  rs  r;   r  r  addressFrom	addressTor  tagFromtagTor"  rq  txidinternalcomment)r	  r'  r  )	rt  r  rd  r  r  r  r  r  r  )r[  r  r  r;   
withdrawId	depositIdr"  r  r	  r  r  r  r  rl  feeCostr  r  r  r  s                      r]  r  zbitmart.parse_transactionP  s   0 %%k=AA
$$[,??	"r)9)9DBB#)r//DB!!+/?@@%%k<@@	%%k:>>
	!u%%))"((--!--eQ77
 ,,UA66	&&z8<<..t/?/?X/V/VWW"";66  C W55"";	::{N;;
K
"
 
 f	

 t..y99
 w
 4
 
 3
 t
 T
 f
 D
 t
 D
  !
" t#
$ (1A~~D4=NNY///)
 
 
 	
r^  c                    |                                   |                     |          }|                     |          }|d         |d         |                     ||          d}|                     |                     ||                    }|                     |di           }	|                     |	|          }
|                     |
||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  rc  parse_margin_loanr[  r  r  r  re  r  r  r  rf  r`  r  s              r]  repay_isolated_marginzbitmart.repay_isolated_margin  s     	V$$==&&Tl 00v>>
 

 <<T[[RX=Y=YZZ ~~h33,,T8<<{{;)
 )
   	r^  c                    |                                   |                     |          }|                     |          }|d         |d         |                     ||          d}|                     |                     ||                    }|                     |di           }	|                     |	|          }
|                     |
||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  rc  r  r  s              r]  borrow_isolated_marginzbitmart.borrow_isolated_margin  s     	V$$==&&Tl 00v>>
 

 ==dkk'SY>Z>Z[[ ~~h33,,T8<<{{;)
 )
   	r^  c                 h    |                      |dd          |                     d |          d d d d |dS )N	borrow_idrepay_id)r;   r  r  r  r	  r'  rs  )r7  r  )r[  rs  r  s      r]  r  zbitmart.parse_margin_loan  sJ     $$T;
CC//h??
 
 	
r^  c                 p   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |dg           }|                     |dg           }|                     ||          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  rc  rw  parse_isolated_borrow_rate)	r[  r  re  r  r  rf  r`  r~  
borrowRates	            r]  fetch_isolated_borrow_ratez"bitmart.fetch_isolated_borrow_rate  s     	V$$fTl
 ;;DKKQW<X<XYYB ~~h33..y"55^^GQ33
..z6BBBr^  rs  c           
         |                      |d          }|                     ||          }|                     |di           }|                     |di           }|                      |d          }|                      |d          }||                     |          |                     |d          |                     |          |                     |d          dd d |d	S )Nr  r  r  r  hourly_interesti6 )	r  r  baseRater  	quoteRateperiodr	  r'  rs  )rt  r  rc  r  r  )	r[  rs  r  r?  r  baseData	quoteDatar  r  s	            r]  r  z"bitmart.parse_isolated_borrow_rate7  s    0 ##D(33!!(F33>>$33NN4"55	!!(J77""9j99++F33((3DEE,,W55)))5FGG

 

 
	
r^  c                     |                                   |                     |          }|                     |di           }|                     |dg           }|                     |          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  rc  rw  parse_isolated_borrow_rates)r[  re  rf  r`  r~  s        r]  fetch_isolated_borrow_ratesz#bitmart.fetch_isolated_borrow_ratesa  sj     	;;FCCB ~~h33..y"55//888r^  fromAccount	toAccountc                 T   |                                   |                     |          }|                     ||          }||d         d}|                     |          }	|                     |          }
|dk    r|dk    rd|d<   |
|d<   nF|dk    rd	|d
<   n:|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*|                     |                     ||                    }n5|dk    s|dk    r)|                     |                     ||                    }| 	                    |di           }|                     | 
                    ||          d|                     |                     |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   inr[  r  rL   spot_to_contractr"  outcontract_to_spotz? transfer() requires either fromAccount or toAccount to be spotNr`  rl  r  message)r  r  r  convert_type_to_accountr'   r;   'privatePostSpotV1MarginIsolatedTransferr  $privatePostAccountV1TransferContractrc  parse_transferparse_transfer_statusr7  )r[  r  r  r  r  re  r  amountToPrecisionr  fromIdtoIdrf  r`  s                r]  r   zbitmart.transfer  s    	==&& 66tVDD' 
 
 --k::++I66&  H$$"&$(!!f$$"4&  h&&"'$*!!&&"4#DG.o$oppp8##h)>)>CCDKKPWY_D`D`aaHHV##f)<)<@@WV\A]A]^^H2 ~~h33{{4..tX>>d001C1CHfV_1`1`aaA
   	r^  c                 <    dddd}|                      |||          S )Nrn  )r   OKFINISHEDr   r  s      r]  r  zbitmart.parse_transfer_status  s1    
 

 &&999r^  c                 :    ddd}|                      |||          S )NrJ   rL   r  r  r   r[  r"  typess      r]  parse_transfer_to_accountz!bitmart.parse_transfer_to_account  .     & &
 
 tT222r^  c                 :    ddd}|                      |||          S )NrL   rJ   r  r   r  s      r]  parse_transfer_from_accountz#bitmart.parse_transfer_from_account  r  r^  r   c                    |                      |d          }|                     |d          }|                      |d          ||                     |          |                     ||          |                     |d          |                     |                      |d                    |                     |                      |d                    |                     |                      |d                    dS )Nr  r	  transfer_idr  r"  r  )r;   r	  r'  r  r  r  r  rl  )rt  rd  r  r  r  r  r  r  )r[  r   r  r  r	  s        r]  r  zbitmart.parse_transfer  s    4 %%h
;;
%%h<<	""8];;"Y////
HEE&&x::;;D<L<LXW]<^<^__778H8HSY8Z8Z[[001A1A(G1T1TUU	
 	
 		
r^  c                 >   |                                   |d}|                     |dd          |d}d}| |                     |          }|d         |d<   |||d<   |||d	<   |                     |d
          }|                     |d|          }|                     |d
g          }|||d<   |                     |                     ||                    }	|                     |	di           }
|                     |
dg           }|                     ||||          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  rB  r;   r  
time_startrB  r  time_endr`  r  )	r  rd  r  ru  (privatePostAccountV1TransferContractListr  rc  rw  parse_transfers)r[  r  rs  rB  re  r  r  r  r  rf  r`  r  s               r]  fetch_transferszbitmart.fetch_transfers  sI    	=E%%ffa88
 
 }}T**H"*4.GJ$)GL!$GG!!&'22##FJ>>6G9--")GJ@@WV\A]A]^^( ~~h33..y"55##GXueDDDr^  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |||d<   |                     |                     ||                    }|                     |di           }	|                     |	dg           }
|                     |
|          }| 	                    ||||          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>`
        Nz1 fetchBorrowInterest() requires a symbol argumentr  r;   rk  r  r`  r  )
r'   r;   r  r  *privateGetSpotV1MarginIsolatedBorrowRecordr  rc  rw  parse_borrow_interestsfilter_by_currency_since_limit)r[  r  r  rs  rB  re  r  r  rf  r`  rowsr  s               r]  fetch_borrow_interestzbitmart.fetch_borrow_interestN  s     >#DG.a$abbbV$$fTl
  GCL$)GL!BB4;;wX^C_C_``, ~~h33~~dIr22..tV<<228T5%PPPr^  c                    |                      |d          }|                     ||          }|                     |d          }||                      |d          |                     |                      |d                    |                     |d          |                     |d          |                     |d          d||                     |          d	S )	Nr  rU  r  interest_amountr  borrow_amountr  )	rs  r  r  r  interestRateamountBorrowedr1  r	  r'  )rt  r;  rd  r  r  r  )r[  rs  r  r?  r	  s        r]  parse_borrow_interestzbitmart.parse_borrow_interest  s     ##D(33!!(F33%%dM::	&&vx88//0@0@z0R0RSS((/@AA ,,T3DEE"..t_EE$"Y//

 

 
	
r^  c                 R   |                                   |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          S )aj  
        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:
        rk  z3 fetchOpenInterest() supports contract markets onlyr  r;   r`  )r  r  r(   r;   #publicGetContractPublicOpenInterestr  rc  parse_open_interestr  s          r]  fetch_open_interestzbitmart.fetch_open_interest  s     	V$$j! 	^TW'\\]]]fTl
 ;;DKKQW<X<XYY ~~h33''f555r^  c           	      2   |                      |d          }|                     |d          }|                     |                     ||          |                     |d          |                     |d          ||                     |          |d|          S )Nr	  r  open_interestopen_interest_value)r  openInterestAmountopenInterestValuer	  r'  rs  )rd  rt  safe_open_interestr  r  r  )r[  r  r  r	  r;   s        r]  r  zbitmart.parse_open_interest  s     %%h<<	h11&&&&r622"&"2"28_"M"M!%!1!1(<Q!R!R"Y//(
 (
   	r^  r=  c                    |t          | j        dz             d}|                     d|          \  }}|                     d|dddg           |                                  |                     |          }|d         st          | j        dz             |d	         t          |          |d
}|                     | 	                    ||                    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   r1  r  r=  rL   z+ setLeverage() supports swap contracts onlyr;   )r  r=  r>  )
r'   r;   r  check_required_argumentr  r  r)   r  (privatePostContractPrivateSubmitLeverager  )r[  r=  r  re  r1  r  r  s          r]  set_leveragezbitmart.set_leverage  s     >#DG.Y$YZZZ
!??vVV
F$$]Jz[bNcdddV$$f~ 	UDG&SSTTTTlH#
 

 <<T[[RX=Y=YZZZr^  c                 R   |                                   |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          S )an  
        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  rc  parse_funding_rater  s          r]  fetch_funding_ratezbitmart.fetch_funding_rate  s     	V$$f~ 	ZDG&XXYYYfTl
 ::4;;wPV;W;WXX" ~~h33&&tV444r^  c           
         |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	g }
t          dt          |	                    D ]}|	|         }| 
                    |d          }|                     ||d	d
          }|                     |d          }|
                    |||                     |d          ||                     |          d           |                     |
d          }|                     ||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>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentr  r;   rB  r`  r  r   r  rL   funding_timefunding_rate)rs  r  fundingRater	  r'  r	  )r'   r;   r  r  )publicGetContractPublicFundingRateHistoryr  rc  rw  r  r  rt  r  rd  r  r  r  sort_byfilter_by_symbol_since_limit)r[  r  rs  rB  re  r  r  rf  r`  r  ratesr  r  r?  symbolInnerr	  sorteds                    r]  fetch_funding_rate_historyz"bitmart.fetch_funding_rate_history  s    >#DG.e$efffV$$fTl
 $GGAA$++gW]B^B^__" ~~h33fb11q#f++&& 	 	A1IE''x88H**8VS&IIK))%@@ILL%#//~FF& LL33      e[11009I5RWXXXr^  c                 <   |                      |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 iS )Nr  r	  r
  r$  fundingTimenextFundingTimers  	markPricer6  r  estimatedSettlePricer'  r&  expected_ratefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRate
rate_valuepreviousFundingTimestamppreviousFundingDatetimeinterval)rt  r8  rd  r  r  r  r  )r[  rk  r  r?  r	  r4  r7  s          r]  r!  zbitmart.parse_funding_rateL  s   2 ##Hh77''+tDD	..xWW#00;LMM
H
d&&x88
 
 $	

 D
 #D
 
 Y//
 4--hWW
  0
 t||,<==
 t//:KLL
 #$8
 "4<<0D#E#E
 "4#3#3Hl#K#K
  '!
" &t#
$ %
 
 	
r^  c                 B   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          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  rw  rc  parse_position)r[  r  re  r  r  rf  r`  firsts           r]  fetch_positionzbitmart.fetch_position~  s     	V$$fTl
 99$++gv:V:VWW< ~~h33tQ++""5&111r^  c                 J   |                                   d}d}|:t          |          }|                     |d          }|                     |          }i }|dk    r|d         |d<   |                     |                     ||                    }|                     |dg           }g }	t          dt          |                    D ]0}
|	                    | 	                    ||
                              1| 
                    |          }|                     |	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  rt  r  #privateGetContractPrivatePositionV2r  rw  r  r  r@  rH  filter_by_array_positions)r[  r~  re  r  symbolsLengthrA  r  rf  	positionsr  r  s              r]  fetch_positionszbitmart.fetch_positions  s&    	LLM$$Wa00E[[''FA &tGH;;DKKQW<X<XYY< NN8VR88	q#i..)) 	= 	=AMM$--il;;<<<<%%g..--fhOOOr^  positionc                 R   |                      |d          }|                     ||          }|d         }|                     |d          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }	t          j        ||          }
t          j        ||	          }|                     i d|dd d|d|d	|                     |          d
d dd d|dk    rdndd|                     |d          d|                     |d          d|                     |d          d|                     |d          dd d|                     |          d|                     |d          d|                     |	          dd d |                     |          |                     |
          |                     |d          |                     |d          d d d |                     |          d d d          S )Nr  r	  position_typemaintenance_margincurrent_valueposition_crossrs  r;   r'  lastUpdateTimestampr9  r[  r   longshort	contractscurrent_amountr  
entryPriceentry_pricer1  
mark_price	lastPricerZ  r=  
collateralinitialMarginunrealized_valuerealized_value)initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentageunrealizedPnlrealizedPnlliquidationPricer1  r   marginRatior5  r6  )	rt  r;  rd  r6   
string_divsafe_positionr  r  rZ  )r[  rI  r  r?  r  r	  r[  r]  rZ  rX  r^  rb  s               r]  r@  zbitmart.parse_position  s   . ##Hh77!!(F33!%%h<<	  ?;; ,,X7KLL##Ho>>%%h0@AA
&-&89JH&U&U#():JGG!! #
H#
$#
 f#
 	#

 Y//#
 "4#
 d#
 tqyyFFw#
 ))(4DEE#
 D,,V^DD#
 $**8]CC#
 ))(LAA#
 #
 ))(33#
 ((:>>#
  $++J77!#
" T##
$ (,!%!2!23D!E!E+/+<+<=X+Y+Y!--h8JKK++H6FGG $,,[99!#9#
 #
 #
   	r^  c                    |t          | j        dz             |                                  |                     |          }|d         st	          | j        dz             d|d         i}|||d<   |                     d||          \  }}|                     |                     ||                    }|                     |d	g           }g }	t          d
t          |                    D ];}
||
         }|                     |d          }|dk    r|	                    |           <|                     |	|||          S )ax  
        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>`
        Nz1 fetchMyLiquidations() requires a symbol argumentrL   z1 fetchMyLiquidations() supports swap markets onlyr  r;   r  rp  r`  r   r"  	liquidate)r'   r;   r  r  r.   r  ry  r  rw  r  r  rt  r  parse_liquidations)r[  r  rs  rB  re  r  r  rf  r`  r  r  r  checkLiquidations                r]  fetch_my_liquidationszbitmart.fetch_my_liquidations*  sV    >#DG.a$abbbV$$f~ 	^tw)\\]]]fTl
 $)GL!22:wOO==dkk'SY>Z>Z[[4 ~~h33q#d))$$ 	% 	%AGE#//v>>;..e$$$&&vvueDDDr^  c                 |   |                      |d          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }t          j        ||          }t          j        ||          }	|                     ||                     ||          |                     |          |                     |          |                     |          |                     |          |                     |	          ||                     |          d	          S )Nr  r  r  r  r  )	rs  r  rR  r  rN  	baseValue
quoteValuer	  r'  )rt  rd  r6   r=  safe_liquidationr  rZ  r  )
r[  liquidationr  r?  r	  contractsStringcontractSizeStringr  baseValueStringquoteValueStrings
             r]  parse_liquidationzbitmart.parse_liquidationf  s6   & ##K::%%k=AA	**;DD!--fnEE&&{4DEE!,_>PQQ"-o{KK$$&&x88**?;; --.@AA&&{33**?;;++,<=="Y//
&
 
&
 
 
 
	r^  c                 ^   |                                   |                     |          }|d         s#t          | j        dz   |d         z   dz             |                     |d          }	|                     |d          }
|                     |g d          }|                     |di           }|                     |d	i           }|                     |d
          }|                     |d
          }|du}|	du}|
du}|du}|du}|dk    }d|d         i}|                     |d          }||                     |d          }||d<   |||d<   |                     |g d          }d}|s|s|r5|                     |dd          |d<   || 	                    ||          |d<   |rI||d<   | 	                    ||          |d<   | 
                    |                     ||                    }n|s|re||d<   |r| 	                    ||	          |d<   n| 	                    ||
          |d<   |                     |                     ||                    }n(|s|r|r4|                     |dd          |d<   | 	                    ||          |d<   n3|                     |dd          |d<   | 	                    ||          |d<   |                     |                     ||                    }n|rx|                     |          |d<   ||                     ||          |d<   || 	                    ||          |d<   |                     |                     ||                    }nt          | j        dz             |                     |di           }|                     ||          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 supportedr5  r6  r  stopLoss
takeProfitr2  NrB  r  r;   r  r  rd  )r2  r  r5  r6  ru  rv  r;  r   r:  r  categorypreset_stop_loss_price_typepreset_stop_loss_pricepreset_take_profit_price_typepreset_take_profit_pricerW  rN  zK editOrder() only supports limit, trigger, stop loss and take profit ordersr`  )r  r  r.   r;   rt  r9  rc  ru  rd  rC  )privatePostContractPrivateModifyPlanOrderr  )privatePostContractPrivateModifyTpSlOrder/privatePostContractPrivateModifyPresetPlanOrderr  r@  *privatePostContractPrivateModifyLimitOrderr  )r[  r;   r  r"  r[  r  rN  re  r  r5  r6  r2  ru  rv  presetStopLosspresetTakeProfitr!  r  r   isPresetStopLossisPresetTakeProfitrF  r  r  rf  r`  s                             r]  
edit_orderzbitmart.edit_order  sh   4 	V$$f~ 	Jtw)IIFSYNZ  ^I   I  J  J  J((AA**63DEE))&2`2`2`aa>>&*b99^^FL"==
))(NCC++JGG%T1"$.
&d2)5-T9fTl
 ((AA$YYv77F)6G%&>"$GJ6#~#~#~ 	TZ 	T< 	T$($5$5flA$N$NGL! -1-D-DVU-S-S)* 9	x"GFO'+'>'>v|'T'TGO$EEdkkRY[aFbFbccHH  +	x< +	x"&GJ \+/+B+B6=+Y+Y((+/+B+B6?+[+[(EEdkkRY[aFbFbccHH  	x!3 	x h9=9J9J6S_ab9c9c56484K4KFTb4c4c011;?;L;LVUacd;e;e786:6M6MfVf6g6g23KKDKKX_agLhLhiiHH  	x"&"3"3B"7"7GJ!"&":":66"J"J #'#:#:65#I#I FFt{{SZ\bGcGcddHHtw)vvwww~~h33f---r^  c                 N   |                                   d}||                     |          }i }|                     d||          \  }}|                     dd|||          }|                     |          }|                     |dg           }	|                     |	|||          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-entry-structure>`
        Nrp  r   r`  )r  r  r  fetch_transactions_request+privateGetContractPrivateTransactionHistoryrw  parse_ledger)
r[  r  rs  rB  re  r  r  transactionsRequestrf  r`  s
             r]  fetch_ledgerzbitmart.fetch_ledger  s     	}}T**H22:wOO"==aueU[\\CCDWXX& ~~h33  x>>>r^  itemc                 Z   |                      |d          }d }t          j        |d          rd}t          j        d|          }nd}|                      |d          }|                     ||          }|                     |d          }|                      |d          }|                     ||                      |d	          |d d |                      |d
          |                     |          |d         |                     |          || 	                    |          d d d d d|          S )Nr  r   r  z-1r  assettimer"  tran_idr`  r  )rs  r;   	directionr  referenceAccountreferenceIdr"  r  r  r	  r'  r  r  rl  r  )
rt  r6   	string_ler=  r  rd  safe_ledger_entryparse_ledger_entry_typerZ  r  )r[  r  r  r  r  r  r	  r"  s           r]  parse_ledger_entryzbitmart.parse_ledger_entry-  sF    !!$11	VS)) 	I'f55FFI%%dG44
%%j(;;%%dF33	f--%%""433" $++D)<<0066 (''//"Y//'
 '
  !  	r^  c                 @    dddddd}|                      |||          S )Nr  rR  r   
settlement)zCommission FeezFunding FeezRealized PNLTransferzLiquidation Clearancer   )r[  r"  
ledgerTypes      r]  r  zbitmart.parse_ledger_entry_typeV  s7    # #"%1
 

 
D$777r^  flowTypec                     i }|||d<   d }| |                      |          }|d         |d<   |||d<   |||d<   |                     d||          \  }}|                     ||          S )N	flow_typer;   r  r  	page_sizerp  )r  r  r  )r[  r  r  rs  rB  re  r  r  s           r]  r  z"bitmart.fetch_transactions_request`  s    #+GK [[((F &tGH$)GL!#(GK 22:wOO{{7F+++r^  c                 N   |                                   d}||                     |          }i }|                     d||          \  }}|                     d||||          }|                     |          }|                     |dg           }	|                     |	|||          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>`
        Nrp  r   r`  )r  r  r  r  r  rw  parse_funding_histories)
r[  r  rs  rB  re  r  r  r  rf  r`  s
             r]  fetch_funding_historyzbitmart.fetch_funding_historyo  s     	[[((F22:wOO"==aPUW]^^CCDWXX& ~~h33++D&%GGGr^  c           
      b   |                      |d          }|                      |d          }|                     |d          }||                     ||d d          |                     |          ||                     |          |                      |d          |                     |d          dS )Nr  r  r  rL   r  r  )rs  r  r  r	  r'  r;   r  )rt  rd  r  r  r  r  )r[  rk  r  r?  r  r	  s         r]  parse_funding_historyzbitmart.parse_funding_history  s     ##Hh77%%h88
%%h77	&&xvFF++J77"Y//""8Y77&&x::
 
 	
r^  c                    g }t          dt          |                    D ]3}||         }|                    |                     ||                     4|                     |d          }|                     |||          S )Nr   r	  )r  r  r  r  r(  filter_by_since_limit)	r[  rR  r  rs  rB  r  r  rk  r,  s	            r]  r  zbitmart.parse_funding_histories  s    q#i..)) 	H 	HA |HMM$44XvFFGGGGfk22))&%???r^  c                    |                                   d }| |                     |          }|d         }|g}|                     |          }|                     |di           }|                     |dg           }	|                     |	|d          }
g }t          dt          |
                    D ]C}|
|         }|d u p|d         |k    }|d u p|d         |k    }|r|r|                    |           D|S )Nr  r`  r  Fr   noter  )	r  r  &privateGetAccountV1WithdrawAddressListrc  rw  parse_deposit_addressesr  r  r  )r[  r  r  r  re  codesr  rf  r`  r  allAddresses	addressesr  r  	noteMatchnetworkMatchs                   r]  fetch_withdraw_addressesz bitmart.fetch_withdraw_addresses  s    }}T**HF#DFE>>vFF* ~~h33~~dFB//33D%GG	q#l++,, 	* 	*A"1oGC76?d+BI'4/WWY5G;5VL *\ *  )))r^  r9  c                     |                                   d}|rd}nd}d|i}|                     |                     ||                    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  )r[  r9  r  re  positionModer  s         r]  set_position_modezbitmart.set_position_mode  s`     	 	*'LL)L\
 ==dkk'SY>Z>Z[[[r^  c                     |                      |          }|                     |d          }|                     |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  )rs  r9  )(privateGetContractPrivateGetPositionModerc  rt  )r[  r  re  rf  r`  r  s         r]  fetch_position_modezbitmart.fetch_position_mode  s[     @@HH ~~h//''o>>#|3
 
 	
r^  c                 F    |                                  | j        d         z
  S )Nr%  )r  rU  )r[  s    r]  noncezbitmart.nonce  s!      ""T\2B%CCCr^  r   GETc                 |   |                     d          }|                     |dd          }|dk    s|dk    rdnd}	|                     | j        d         |	                   }
|
dz   |                     ||          z   }|                     ||                     |                    }d}|dk    p|d	k    }|r|r|                     |          }|d
|z   z  }|dk    r|                                  t          | 
                                          }|                     | j        dd          }| j        ||dd}|s|                     |          }|}|dz   | j        z   dz   |z   }|                     |                     |          |                     | 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  rt  implode_hostnamer   implode_paramsru  extract_params	urlencodecheck_required_credentialsr  r  rU  r   jsonr   hmacencoder   hashlibsha256)r[  pathr   r  re  r  r  r  rw  r  baseUrlr   queryqueryStringgetOrDeleter	  r,  auth	signatures                      r]  signzbitmart.sign!  s   

3##E1f55$..(i2G2Gf''	%(8(@AAmd11$???		&$"5"5d";";<<?Fh,> 	) )"nnU33s[(()++---DJJLL))I''jBSTTH K"+"* 2	 G  #yy''"s?TX-3kAD		$++d"3"3T[[5M5Mw~^^I#,GK fdwOOOr^  reasonr   r  r  r  c
                    |d S |                      |d          }
|
                                }|
d uo|dk    o|dk    }|                      |d          }|d uo|dk    }|s|r| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         |
|           |                     | j        d         ||           |                     | j        d         ||           t          |          d S )	Nr  rn  successr  r    r  r  )rt  lowerr;   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr#   )r[  r  r  r   r  r  r  rf  requestHeadersrequestBodyr  messageLowerisErrorMessage	errorCodeisErrorCodefeedbacks                   r]  handle_errorszbitmart.handle_errorsA  s+   4 ""8Y77}}!-iLD4Hi|_hOh$$Xv66	 ,G93F 	*. 	*w}t+H001I7T\]]]001I7T\]]]001I9V^___001I9V^___)))tr^  )N)NNN)__name__
__module____qualname__r   rY  r   rg  r|  r"   r    r  r  r   r  r   r  r   r  r  r  r	   r  r  dictr   rA  rF  r   r   rL  r   rQ  r   rr  rx  r  r  r  r  r  r   r  r  r  r   r  r  r   r  rk  r  floatr  r   r   r   r  r   r/  r  r  rY  rb  rh  rn  ru  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  r  r?  r  r   r"  r-  r!  rB  r   rH  r@  ri  rs  r  r   r  r  r  r  r   r  r  r  r  boolr  r  r  r  r  __classcell__)r\  s   @r]  r8   r8   !   s       T# T T T T T Tl !# 6 6s 6 6 6 6. #% =
 =
 =
 =
~ )+ a atO/D a a a aF -/ q q43H q q q qf $& 1 1$v, 1 1 1 1" ') \ \Z \ \ \ \|D# DTW D\_ D D D D8 79 %
 %
# %
 %
 %
 %
N
 
 
 
 
 
, <>  5  5s  5  5  5  5DY Y4 Y Y6 Y Y Y Yv 02 ]1 ]13 ]1f ]1 ]1 ]1 ]1~ 04B hG hGW hG7 hG hG hG hGT :>b IH IHs IH3 IHY IH IH IH IHVd d dv d d d d dL 6:UW '= '=3 '=s '=# '=\`af\g '= '= '= '=R< < <4 < < < <| 9=4^bkm aI aI# aI# aIS aIX[ aIrvw{r| aI aI aI aIF -1tRV_a i= i=c i= i=C i= i= i= i=V 9=4^bkm ; ;S ;# ;S ;X[ ; ; ; ;,"-H "- "- "- "-H   $& }? }?( }? }? }? }?~
 
T 
6 
EX 
 
 
 
& 57 , , ,;N , , , ,Bz z zv z z z z zx3 3 3: : :2 RT N N N5 N N N N$ gksu W W3 Wi Wy WRW W`c W W W Wr @B ? ?D$6 ? ? ? ?B tx  AC x, x, x,9 x,I x,_d x,mp x, x, x, x,t tx  AC Z, Z, Z,9 Z,I Z,_d Z,mp Z, Z, Z, Z,x 37r [ [s [C [ [ [ [z ;?r 6 6c 6C 6dSXk 6 6 6 6p /32 :5 :5 :5 :5 :5 :5x <@daenp 3? 3?S 3? 3?[^ 3? 3? 3? 3?j /3TXac @= @= @=3 @=c @=hlmrhs @= @= @= @=D 154VZce := :=# :=S :=PS :=jnotju := := := :=x 37TX\eg 	U 	UC 	Us 	URU 	U 	U 	U 	U 26b l. l.c l.3 l. l. l. l.\ 79  :  :#  :^  :  :  :  :D&
 &
n &
 &
 &
 &
P KOWY - -S -% -# -C -^i - - - -^ <@daenp -H -HS -H -H[^ -H -H -H -H^ 26b (. (. (.3 (. (. (. (.T *.Dt\^ V V3 Vc V Vcghsct V V V V 59 (. (.3 (.c (. (. (. (.T -1tRV_a W Wc W WC Wfjkvfw W W W W	:s 	: 	: 	: 	:L
 L
T L
X L
Q\ L
 L
 L
 L
\ LN $ $C $s $ $ $ $L TV $ $S $ $U $ $ $ $L
 
 
 
 
 
0 >@ 3C 3C 3CDV 3C 3C 3C 3Cj(
 (
t (
V (
Oa (
 (
 (
 (
T 24 -9 -98K -9 -9 -9 -9^ [] E ES E% Ec Ec Ean E E E EN:C :C : : : :3 3 33 3 3%
 %
t %
x %
= %
 %
 %
 %
N +/TPT]_ 8E 8EC 8Es 8E# 8Edhivdw 8E 8E 8E 8Et 15DW[jnwy 1Q 1Q# 1Qc 1QQT 1Qdg 1Q  C  DR  S 1Q 1Q 1Q 1Qf
 
$ 
 
. 
 
 
 
8 79  6  6#  6  6  6  6D F    ( 9=R [ [S [# [ [ [ [8 68 #5 #5 #5K #5 #5 #5 #5J 8<$]ajl 6Y 6Y 6YC 6YWZ 6Y 6Y 6Y 6Yp0
 0
6 0
[ 0
 0
 0
 0
d 24 /2 /2S /2 /2 /2 /2b 26b 9P 9Pw 9PT(^ 9P 9P 9P 9Pv> >t >V > > > >@ 37TX\eg :E :EC :Es :ERU :E :E :E :Ex$ $V $ $ $ $L `drv  @B u. u.S u.# u.Y u.i u.Y\ u.lo u.  GL u. u. u. u.n (,$TZ\ (? (? (?C (?s (?aefqar (? (? (? (?T' 't 'x '; ' ' ' 'R8 8 8 :>T`dsw  AC , ,3 ,s ,Z] ,mp , , , , 37TX\eg (H (HC (Hs (HRU (Hlpq  mA (H (H (H (HT
 
f 
 
 
 
2@ @S @X[ @gklzg{ @ @ @ @ 8<VX & &S & & & &P =A \ \ \c \ \ \ \@ 15R 
 
# 
 
 
 
8D D D &eBSW P P P 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     sl   ( ' ' ' ' ' - - - - - -  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 * * * * * * ) ) ) ) ) ) 3 3 3 3 3 3 4 4 4 4 4 4 % % % % % %|T |T |T |T |Th |T |T |T |T |Tr^  