
    i	                       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 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlm Z  d dlm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dlm)Z) d dlm*Z* d dlm+Z+ d dl,m-Z- d dl,m.Z. d dl/m0Z0  G d dee          Z1dS )    )Exchange)ImplicitAPIN)Balances
CurrenciesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTransaction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 fdZi fdZi fdZi fdZi fdZi fdee	         fdZ
i fdefdZi fd	efd
ZdcdefdZi fd	efdZdcd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dcde	defdZddi fdedededee         fdZdcde	defdZdddi fdedededee         fdZ dddi fde!dedefdZ"dddi fdede!dedefdZ#de$fd Z%d! Z&i fde$fd"Z'dcde	de(fd#Z)i fdede(fd$Z*dcde	de+fd%Z,d& Z-d' Z.i fded(e/fd)Z0di fded*e1d+e2d,e/d-e3f
d.Z4di fded*e1d+e2d,e/d-e3f
d/Z5di fded*e1d+e2d,e/d-e3f
d0Z6di fdede!fd1Z7di fde!fd2Z8dddi fde!dedefd3Z9dddi fde!dededee+         fd4Z:dddi fde!dededee+         fd5Z;dddi fde!dedefd6Z<di fdede!fd7Z=i fd	efd8Z>dcd9Z?dcd:Z@di fd	ed,e/fd;ZAdddi fd	e!dedefd<ZBdi fded	e!fd=ZCdddi fd	e!dededeeD         fd>ZEdi fded	e!fd?ZFdddi fd	e!dededeeD         fd@ZGdA ZHdcdedeDfdBZIi fded	efdCZJi fded	ed,e/fdDZKdcdefdEZLi fdefdFZMdcde	fdGZNi fdHZOi fd	ed,e/dIedJedePf
dKZQdL ZRdM ZSdN ZTdcdefdOZUdddi fd	e!dedefdPZVddddi fd	e!de!dedefdQZWdcde	fdRZXi fdefdSZYdcde	fdTZZdi fdUede!fdVZ[i fdefdWZ\dcde	fdXZ]i fdefdYZ^di fdefdZZ_dcde	fd[Z`dddi fde!dedefd\Zadcde	fd]Zbd^ Zcd_d`i ddfdaZddb Ze xZfS )dbitmartc                 4   |                      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ddddddddddddTdUdVdWdXdYdZid[d\d]d^d_d`dadbddddcdddei dfdgdhdgdidjdkdjdldmdndodpdqdrdmdsdtdudqdvdqdwdmdxdydzdmd{dyd|dod}dmdmd~dmdmdydydodydii ddjddjddmddjddmddjddjddmddyddmddyddddjddjddddmddmi ddmddmddddddddyddmddyddyddddmddddddddddddi ddyddyddyddyddyddjddjddjddjdddddddd~ddddddmddmi ddmddmddddddddddyddyddyddddddēddƓddyddēddƓddēd˜d̜dddgdmd~dyddddddddd՜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dt
          di dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          d t          dt          dt          dt          dt          i dt          dt          dt          dt          d	t          d
t          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          d t          d!t          d"t           d#t          d$t          d%t          d&t          i d't"          d(t$          d)t          d*t          d+t          d,t          d-t          dt          d.t"          d/t          d0t          d1t          d2t&          d3t(          d4t(          d5t(          d6t(          i d7t(          d8t(          d9t(          d:t(          d;t          d<t          d=t          d>t          d?t          d@t          dAt          dBt          dCt          dDt"          dEt          dFt          dGt          i dHt          dIt          dJt(          dKt&          dLt&          dMt&          dNt(          dOt(          dPt(          dQt          dRt          dSt          dTt          dUt"          dVt          dWt          dXt"          i dYt          dZt          d[t          d\t          d]t(          d^t(          d_t          d`t          dat(          dbt(          dct(          ddt(          det(          dft(          dgt(          dht          dit          i djt          dkt          dlt          dmt          dnt          dot          dpt          dqt          drt          dst          dtt          dut          dvt          dwt          dxt          dyt          dzt          i d{t          d|t          d}t          d~t          dt          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i dddddddddddddddii dddddddddddddddÐdÓdĐdēdŐdœdƐdƓdǐdǓdȐdȓdɐdɓdʐdʓdːd˓d̐d̓i d͐d͓dΐdΓdϐdϓdАdГdѐdѓdҐdғdӐdӓdԐdԓdՐdՓd֐d֓dאdדdؐdؓdِdٓdڐdړdېdۓdܐdݓdސdޓi dߐdߓddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddd d ddddddi ddddddddddd	d	d
d
dddddddddddddddddddddddddddddd d!d"d#dd$diddd%dd&d'i          S ((  Nidr-   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createPostOnlyOrder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fetchLiquidationsfetchMarginModefetchMarketsfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransfer)fetchTransfersfetchWithdrawAddressesByNetworkfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModetransferwithdrawhostnamezbitmart.comurlszdhttps://user-images.githubusercontent.com/1294454/129991357-8f47464b-d0f4-41d6-8a82-34122f0d1398.jpgrestzhttps://api-cloud.{hostname}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/klineaccount/v1/currenciesz$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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/get-open-ordersz#contract/private/current-plan-orderzcontract/private/tradesz'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/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-orderg      ?zcontract/private/cancel-ordersz"contract/private/submit-plan-orderz"contract/private/cancel-plan-orderz contract/private/submit-leverage)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)exactbroadcommonCurrencies	GOLDMINERz	Step HeroPACBEYONDzGorilla DiamondGoldariozMVP CoinTruebit)z$GMz$HEROz$PACBPGDTGLDMVPTRUoptionsERC20USDTSOLBTCTRC20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HRC20HECOXDCONELATCSPRCasperICPComputerXTZMINA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)OASYSr  OMAXr  r  r  r  r  r   NEMr  ERGOtyper>   r@   CCXTxBitmart000)defaultNetworkdefaultNetworksnetworksdefaultTyperQ   accountsByType!createMarketBuyOrderRequiresPricebrokerId)deep_extendsuperr-   describeparse_numberr*   r   r   r   r   r%   r&   r'   r   r    r   r#   r   r$   r"   r!   r(   )self	__class__s    R/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/bitmart.pyr  zbitmart.describe#   s7   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
  PPP $P 	P
 %P %P $UP 'P "4P tP P /P ,UP 0P tP  &t!P" '#P P$ (%P& "5'P( -d)P* +P, &t-P. +E/P0 )%1P2 &t3P4 $T5P6 '7P8 (9P: "4;P< =P> &t?P@ (APB 1%CPD  EP P PF *4GPH +EIPJ &tKPL #DMPN *5OPP $UQPR *4SPT +DUPV $UWPX "5YPZ [P\ &t]P^  _P` daPb $TcPd +EePf "4gP P Ph diPj !$kPl umPn #DoPp  qPr $UsPt !$uPv twPx tyPz {P| T}P~ tP@ "4APB #ECPD &tEPF 'GPH  IP PJ #'38#'$( %$)'+#!&  _P P PS
B
v wS
B
x ~: 2;= #  9 yS
B
R "$ $SS
B
\  %q(! -c	
 *3 21 4Q 3A 8 3A 21 3A )! )" 0  (!" 0#$ /%& 34/134129;8:12137  @*>* B3* =a	*
 Fs* Fq* Mc* KC* ,Q* 0* )!* 5b* 5b* >s*  =c!*$ /%*& )!'*( )!)* *, )!-*. )!/*0 /1*4 @5*6 ?7*8 89*: :1;*< ,R=*> +B?*B 0C*F 9!G*H 1#I*J 9"K*L 4RM*N ;CO*P >sQ*R 22S* *V)A2) A") B2	)
 @) A") KC) KC) J3) 4S) /) /) /)  0!)" .q#)$ 5a%)& 4Q')( 7)) )* /+), 5a-)0 /1)2 /3)4 /5)8 6q9): 9";)< 8=)> ;B?)B <RC)D 7E)F 8G)H 8I)J 9"K)L =cM)N =cO)P ;CQ) )YV VAw w]S
B
L  MS
B
j !%"&!..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	"  kS
B
f YgS
B
h 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V YM MiS
B
D "$(!! 	! 	!ES
B
X ")G$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N VOVP 5QV V VR 5SVT 5UVV HWVX :YVZ 5[V\ F]V` WaVb 5cVd $eVf FgVh 5iVj FkVl 5mVn FoVp 5qVr FsVt FuV V Vv WwVx FyVz 5{V| F}V~ 5VF FGVH mIVJ FKVL WMVN FOVP 8QVV FWVX FYVZ W[V\ F]V^ W_Vd 
eV V Vf FgVh 5iVj FkVl 5mVn 5oVp WqVt 5uVv GwVx 9yVz 5{V| F}V~ FV@ FAVD 5EVH 5IVJ WKVL 5MV VN #"("" ""  !eV V Vn  &F! #"# # 6:-Kf fYS
B
 S
B
 S
 S
 S
	    c                     |                      |          }|                     |di           }|                     |d          S )a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :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_valuesafe_integer)r  paramsresponser  s       r  
fetch_timezbitmart.fetch_time  sD     ++F33 x44  }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
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
        rw   r  r  r  serviceservice_typer@   contractNstatus   okmaintenanceend_time)r'  updatedetar   info)r  r  safe_stringomitpublicGetSystemServiceindex_byr  )r  r   r  r  r  r!  r  servicesservicesByTyper$  r'  r-  
statusCodes                r  fetch_statuszbitmart.fetch_status  sS    //$,rBB&&t|]CC==5566**..v664 x44??4B77x@@6>>D//.$77**7H==JQ&''<<
 
 	
r  c                 <   |                      |          }|                     |di           }|                     |dg           }g }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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   symbol	symbol_idbase_currencyquote_currency/min_buy_amountmin_sell_amountbase_min_sizer/   	numericIdbasequotesettlebaseIdquoteIdsettleIdr  r>   Tr?   Fr@   rA   rB   activer&  price_max_precisionamountpriceminmaxbase_max_sizeleveragerK  rL  costlinearinversecontractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr.  )publicGetSpotV1SymbolsDetailsr  rangelenr/  r  safe_currency_coder+   
string_maxsafe_numberappendr  parse_precision)r  r   r!  r  r8  resultimarketr/   rA  rE  rF  rB  rC  r9  
minBuyCostminSellCostminCostbaseMinSizes                      r  fetch_spot_marketszbitmart.fetch_spot_markets	  s   55f==6 x44//$	266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 1b1Y1 &1 	1
 1 $1 &1 71 D1 1 1 %1 1 %1 %1  $!1" E#1$  $"&")!..t/C/CDDTDTU[]rDsDs/t/tuu   $#! !
  +#//HH 
  $# 
  $0099#  $  a1 1 1 1 1 1 1d r  c                    |                      |          }|                     |di           }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |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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  r8  r   r9  r;  r<  r  r=  :product_typer   r(  expire_timestampr/   rA  rB  rC  rD  rE  rF  rG  r  r@   rA   r>   Fr?   rB   rH  Tr&  contract_sizevol_precisionprice_precisionrJ  min_leveragemax_leveragerM  
min_volume
max_volumerQ  open_timestamprT  )
publicGetContractPublicDetailsr  r`  ra  r/  rb  r  re  rd  iso8601)r  r   r!  r  r8  rg  rh  ri  r/   rE  rF  rB  rC  rG  rD  r9  productTypeisSwap	isFuturesrX  s                       r  fetch_contract_marketszbitmart.fetch_contract_marketsi  ss   66v>>B x44//$	266q#g,,'' A	 A	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 1b1T1 &1 	1
 1 &1 &1 71 H1 &6h1 1 %1 1 )1 %1  $!1" D#1$   $ 0 0 I I "&,,v"6"6""..vGG!--f6GHH   $//GG#//GG! !
  $//EE#//EE 
  $# 
  $#  $  ,,V5EFFa1 1 1 1 1 1 1d r  returnc                     |                      |          }|                     |          }|                     ||          S )z
        retrieves data on all markets for bitmart
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        )rn  r  array_concat)r  r   r>   r&  s       r  fetch_marketszbitmart.fetch_markets  s@     &&v....v66  x000r  c                    |                      |          }|                     |di           }|                     |dg           }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }	|                     |d          }
|                     |d          }|                     |d          }|o|}||	|
||||ddddd	ddd	d
d
||	<   |S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  
currenciesr   r/   r0   withdraw_enableddeposit_enabledNrM  )rK  r   )
r/   coder0   r.  rH  depositr   feer\  r]  )publicGetSpotV1Currenciesr  r`  ra  r/  rb  )r  r   r!  r  r  rg  rh  currencyr/   r  r0   withdrawEnableddepositEnabledrH  s                 r  fetch_currencieszbitmart.fetch_currencies  s3    11&99 x44__T<<<
q#j//** 	 	A!!}H!!(D11B**2..D##Hf55D"ooh8JKKO!__X7HIIN$7F  )+!&*488(,T : :  F4LL r  r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|d         }i }|                     |d          ||<   ||i dS )a,  
         * @deprecated
        please use fetchDepositWithdrawFee instead
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r  r/   r  withdraw_fee)r.  r   r  )load_marketsr  !privateGetAccountV1WithdrawChargeextendrd  )r  r  r   r  requestr!  r  withdrawFeess           r  fetch_transaction_feezbitmart.fetch_transaction_fee  s     	==&&
 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   )r.  r   r  r  )rd  )r  r  r  s      r  parse_deposit_withdraw_feez"bitmart.parse_deposit_withdraw_fee1  sM     ''^<<" 
 "  
 
 	
r  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|d         }|                     |          S )a  
        fetch the fee for deposits and withdrawals
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r  r/   r  )r  r  r  r  r  )r  r  r   r  r  r!  r  s          r  fetch_deposit_withdraw_feez"bitmart.fetch_deposit_withdraw_feeG  sz     	==&&
 99$++gv:V:VWW ..t444r  ri  c                    |                      |d          }||                     |dd          }|                     |dd          }|                     ||          }|d         }|                     |dd          }|                     |d          }|[|                     |d	          }|;|d
k    r5|d         }	|	t          j        |                    |	d          d          z   }n|d
k    rd
}|                     |d          }
|                     |d          }||
|                     |d|          }n|
}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+|          S ),N	timestamps_t  r9  contract_symbol	close_24h
last_priceprice_change_percent_24hfluctuationr   r    100base_volume_24hquote_volume_24h
volume_24h	avg_priceindex_pricehigh_24h
high_pricelow_24h	low_pricedatetimehighlowbidbest_bid	bidVolumebest_bid_sizeaskbest_ask	askVolumebest_ask_sizevwapopenopen_24hcloselastpreviousClosechanger   average)
baseVolumequoteVolumer.  )
r  safe_integer_productsafe_string_2safe_marketr/  r+   
string_mulreplacesafe_tickerr|  )r  tickerri  r  marketIdr9  r  r   percentageRaw	directionr  r  r  r  r  s                  r  parse_tickerzbitmart.parse_tickerd  s   ` %%fk::	11&%FFI%%fh8IJJ!!(F33!!!&+|DD%%f.HII
 ,,V]CCM)0D0D)!,	&);M<Q<QR[]_<`<`bg)h)hh

#%% 
%%f.?@@
&&v/ABB!"..v|[QQ )!
$$V[-HH!!&*lCC  K@@ !
f!
!
 Y//!
 D	!

 3!
 4##FJ77!
 ))&/BB!
 4##FJ77!
 ))&/BB!
 D!
 D$$VZ88!
 T!
 D!
 T!
 d!
  *!!
" w#!
$ %&)!
 !
 !
* +  	r  r9  c                    |                                   |                     |          }i }d}|d         r5|d         |d<   |                     |                     ||                    }n`|d         r5|d         |d<   |                     |                     ||                    }n#t          | j        dz   |d         z   d	z             |                     |d
i           }|                     |dg           }d}|d         r|                     |d          }n|d         r|                     |d          }| 	                    ||d                   }	| 
                    |	|          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr@   r/   r  r>   r9  z  fetchTicker() does not support r  1 markets, only spot and swap markets are acceptedr  tickers)r  ri  publicGetContractV1Tickersr  publicGetSpotV1Tickerr#   r/   r  r2  	safe_dictr  )
r  r9  r   ri  r  r!  r  r  tickersByIdr  s
             r  fetch_tickerzbitmart.fetch_ticker  s    	V$$&> 	T)/G%&66t{{7F7S7STTHHF^ 	T &tGH11$++gv2N2NOOHHtw)KKfU[n\  `S   S  T  T  Tl x44//$	266&> 	D--::KKF^ 	D--1BCCKVD\::  000r  r8  c                    |                                   |                     |          }d}d}|+|                     |d          }|                     |          }|                     d||          \  }}d}|dk    r|                     |          }n9|dk    r|                     |          }nt          | j        dz   |z   dz             |                     |di           }|                     |d	g           }i }	t          dt          |                    D ]*}
|                     ||
                   }|d
         }||	|<   +|                     |	d
|          S )a%  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://developer-pro.bitmart.com/en/spot/#get-ticker-of-all-pairs-v2
        :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   ry   r>   r@   z! fetchTickers() does not support r  r  r  r9  )r  market_symbolsr  ri  handle_market_type_and_paramspublicGetSpotV2Tickerr  r#   r/   r`  ra  r  filter_by_array_tickers)r  r8  r   r  ri  r9  r!  r  r  rg  rh  r  s               r  fetch_tickerszbitmart.fetch_tickers  s}    	%%g..__Wa00F[[((F99.&RXYYf6>>11&99HHV^^66v>>HHtw)LLtS  WJ   J  K  K  Kx44//$	266q#g,,'' 	$ 	$A&&wqz22FH%F#F6NN++FHgFFFr  limitc                    |                                   |                     |          }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
        :see: https://developer-pro.bitmart.com/en/spot/#get-depth-v3
        :see: https://developer-pro.bitmart.com/en/futures/#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
        r9  r/   Nr>   r  r@   z# fetchOrderBook() does not support r  r  r  tsr  )
r  ri  publicGetSpotQuotationV3Booksr  publicGetContractPublicDepthr#   r/   r  safe_integer_2parse_order_book)	r  r9  r  r   ri  r  r!  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\ x44''dK@@	$$T6(+;YGGGr  c                    |                      |g d          }d|v }d }d }d }d }|rC|                     |d          }|                     |d          }|                     |d          }nm|                     |g d          }|                     |d          }|                     |d          }|                     |                     |d                    }|                     |d	          }	|                     |	|          }|                     |d
d          }
d }|
H|                     |d          }|                     |          }||dk    r|d         n|d         }|
|d}|                     ||                     |g d          |                     |dd          ||                     |          |d	         |||                     |dd          ||| 	                    |dd          |d|          S )N)
order_time
createTimecreate_timer  countrK  r  )sizevolfillQtynotionalsider9  r  	paid_feesfeeCoinNamebuyrB  rC  rS  r  )tradeIdtrade_idlastTradeIDorderIdorder_idrL  	fillPrice	tradeRole	exec_type)r.  r/   orderr  r  r9  r  r  rL  rK  rS  takerOrMakerr  )
safe_integer_nr/  safe_string_nparse_order_sider  r  rb  
safe_trader|  safe_string_lower_2)r  traderi  r  isPublicTraderK  rS  r  r  r  feeCostStringr  feeCurrencyIdfeeCurrencyCodes                 r  parse_tradezbitmart.parse_trade  sD   r ''/Z/Z/Z[[	%. 	J%%eW55F##E844D##E622DD''/I/I/IJJF##E:66D##E622D(()9)9%)H)HIID##E844!!(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&''wDD 44UKUU 
  
   	r  sincec                    |                                   |                     |          }|d         s#t          | j        dz   |d         z   dz             d|d         i}|                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	|||          S )	a  
        get the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r>   z  fetchTrades() does not support r  & orders, only spot orders are acceptedr9  r/   r  trades)	r  ri  r#   r/   publicGetSpotV1SymbolsTradesr  r  	safe_listparse_trades)
r  r9  r
  r  r   ri  r  r!  r  r  s
             r  fetch_tradeszbitmart.fetch_trades  s     	V$$f~ 	Itw)KKfU[n\  `H   H  I  I  IfTl
 44T[[&5Q5QRR* x44h33  >>>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   r(  r   r   r   r  r  
open_priceor  hr  lclose_pricecvolumev)
isinstancelistsafe_timestamprd  safe_timestamp_2safe_number_2)r  ohlcvri  s      r  parse_ohlcvzbitmart.parse_ohlcv  s   V eT"" 	##E1--  **  **  **  **  **  %%e[$??""5,<<""5,<<""5+s;;""5-==""5(C88 r  r   c           	      ~   |                                   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*|                     |                     |
|                    }n)|                     |                     |
|                    }|                     |dg           }|                     |||||          S )a-  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://developer-pro.bitmart.com/en/spot/#get-history-k-line-v3
        :see: https://developer-pro.bitmart.com/en/futures/#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
        Frl   paginate   r9  r/   Nstepr>   beforegMbP?r  r  r   afteri  
start_timer+  r@   r  )r  handle_option_and_params"fetch_paginated_call_deterministicri  parse_timeframer  r   handle_until_optionparse_to_intrN  millisecondssumpublicGetContractPublicKliner  publicGetSpotQuotationV3Klinesr  parse_ohlcvs)r  r9  	timeframer
  r  r   r#  ri  durationparsedTimeframer  maxLimitnowstartendr!  r   s                    r  fetch_ohlcvzbitmart.fetch_ohlcvQ  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88Wf9U9UVVHH::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          }||}||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[  
        :see: https://developer-pro.bitmart.com/en/spot/#account-trade-list-v4-signed
        :see: https://developer-pro.bitmart.com/en/futures/#get-order-trade-keyed
        fetch all trades made by the user
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :param boolean [params.marginMode]: *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders(only isolated margin orders are supported)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr/   r9  rk   )untilendTimer+  r<  r>   isolated
iso_margin	orderModer  r$  	startTimer=  r@   z+ fetchMyTrades() requires a symbol argumentr(  r+  z" fetchMyTrades() does not support / orders, only spot and swap orders are acceptedr  )r  ri  r  r  r0  handle_margin_mode_and_paramsr  r  r  privatePostSpotV4QueryTradesr  r   r/   privateGetContractPrivateTradesr#   r  r  )r  r9  r
  r  r   ri  r  r  r!  r<  
marginModer  defaultLimitr  s                 r  fetch_my_tradeszbitmart.fetch_my_trades  s+    	[[((F &tGH99/6SYZZf##F,L,L,LMM6G9--6>>J!%!C!COU[!\!\JZ'''3$oodlORHHG,,WgsCCL}$$GG ',$ %*	"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*  
        :see: https://developer-pro.bitmart.com/en/spot/#order-trade-list-v4-signed
        fetch all the trades made from a single order
        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r  r  N)r  !privatePostSpotV4QueryOrderTradesr  r  r  )	r  r/   r9  r
  r  r   r  r!  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<   |                     |dd          |d<   |||<   |                     |          S )Nr  r@   r?   r8  walletr.  r   r9  _rB  rC  r  r/   	coin_code	availableavailable_balancefreefrozenfrozen_balanceused)
r  r`  ra  r/  safe_symbolrb  parse_balance_helpersafe_balancer  account)r  r!  
marketTyper  rM  rg  rh  entryr  r9  rB  rC  baseCode	quoteCode	subResultbalance
currencyIdr  rY  s                      r  custom_parse_balancezbitmart.custom_parse_balance'  sn   x44__Xvr::FF8##__T9b99FF__T8R88F(#!!1c&kk** > >q	++E8<<))(D#>>ufb99w;;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"4WhHX"Y"Y&t$$V,,,r  c                 L   |                                  }|                     |d          |d<   |                     |d          |d<   |                     |d          |d<   |                     |d          }|                     |d          }t          j        ||          |d	<   |S )
NrS  rU  rP  rR  total_assettotalborrow_unpaidinterest_unpaiddebt)rY  r/  r+   
string_add)r  r[  rY  rg  interests        r  rW  zbitmart.parse_balance_helperK  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 )as  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://developer-pro.bitmart.com/en/spot/#get-spot-wallet-balance
        :see: https://developer-pro.bitmart.com/en/futures/#get-contract-assets-detail
        :see: https://developer-pro.bitmart.com/en/spot/#get-account-balance
        :see: https://developer-pro.bitmart.com/en/spot/#get-margin-account-details-isolated
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrQ   rF  r?   Fr>   r@   rY  z! fetchBalance() does not support zE markets, only spot, swap and account and margin markets are accepted)r  r  r/  	safe_boolr0  privateGetSpotV1Wallet%privateGetContractPrivateAssetsDetailprivateGetAccountV1Wallet%privateGetSpotV1MarginIsolatedAccountr#   r/   ra  )r  r   rZ  rF  isMarginr!  s         r  fetch_balancezbitmart.fetch_balanceU  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  c                     |                      |d          }|                     |          }|||                     |d          |                     |d          d d dS )Nr9  maker_fee_ratetaker_fee_rate)r.  r9  r   r   r   r   )r/  rV  rd  )r  r  ri  r  r9  s        r  parse_trading_feezbitmart.parse_trading_fee  so     ##C22!!(++%%c+;<<%%c+;<<
 
 	
r  c                 f   |                                   |                     |          }|d         s#t          | j        dz   |d         z   dz             d|d         i}|                     |                     ||                    }|                     |d          }|                     |          S )a  
        fetch the trading fees for a market
        :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>`
        r>   z$ fetchTradingFee() does not support r  r  r9  r/   r  )r  ri  r#   r/   privateGetSpotV1TradeFeer  r  ru  r  r9  r   ri  r  r!  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 x00%%d+++r  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$          |                     |g d%          d |                     ||                     |d&d'                    d d d(|          S ))Nr  r  r  r  r9  r  r>   limit_makerr  TPOiocIOCrL  zmarket priceactivation_pricer/   clientOrderIdclient_order_idr.  r  r  lastTradeTimestampupdate_timetimeInForcepostOnlyr  	stopPricetriggerPricerK  r  rS  filled_notionalfilledNotionalr  )	price_avgpriceAvgdeal_avg_price)filled_size
filledSize	deal_sizer'  state)filled	remainingr'  r  r  )r  strr  r  r/  rV  r  rd  
safe_orderr|  r  r  	omit_zeror   parse_order_status_by_type)r  r  ri  r/   r  r  r9  	orderTyper  r  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--e5FGG 
 E 
 	 

 Y// 
 !$"3"3E="I"I 
 f 
 D 
 ; 
  
 D))$*:*:5&*I*IJJ 
 T^^K00 
 0 
 3 
 dnnT%5%5eV%D%DEE 
  D&&u.?AQRR! 
" t))%1\1\1\]]# 
$ ((0Z0Z0Z[[55iASASTY[celAmAmnn- 
  
  
. /  	r  c                 >    ddddd}|                      |||          S )Nr  sell)1234r/  )r  r  sidess      r  r  zbitmart.parse_order_side  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	  )r  r/  )r  r  r'  statusesByTypestatusess        r  r  z"bitmart.parse_order_status_by_type  s      $*"&0   
 
* ??>4<<&&999r  rS  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
        :see: 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>`
        r>   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  ri  r  N)r  ri  r#   r/   create_order)r  r9  rS  r   ri  s        r  !create_market_buy_order_with_costz)bitmart.create_market_buy_order_with_cost  ss     	V$$f~ 	ftw)ddeee6;23  5$fMMMr  r  r  rK  rL  c                    |                                   |                     |          }|                     d|          }|                     |d          }	|                     |g d          }
|
du}d}|d         rL|                     ||||||          }|	dk    r|                     |          }n]|                     |          }nG|                     ||||||          }|r| 	                    |          }n| 
                    |          }|                     |di           }|                     ||          }||d<   ||d	<   ||d
<   ||d<   |S )a  
        create a trade order
        :see: https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
        :see: https://developer-pro.bitmart.com/en/spot/#place-margin-order
        :see: https://developer-pro.bitmart.com/en/futures/#submit-order-signed
        :see: https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market', 'limit' or 'trailing' for swap markets only
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, 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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rK   r   r  r  trigger_priceNr>   r>  r  r  r  rK  rL  )r  ri  rC  r/  r   create_spot_order_request"privatePostSpotV1MarginSubmitOrderprivatePostSpotV2SubmitOrdercreate_swap_order_request)privatePostContractPrivateSubmitPlanOrder%privatePostContractPrivateSubmitOrderr  r  )r  r9  r  r  rK  rL  r   ri  rg  rF  r  isTriggerOrderr!  spotRequestswapRequestr  r  s                    r  r  zbitmart.create_order  s   4 	V$$33M6JJ%%fa00
))&2`2`2`aa%T1&> 	S88tVUZ\bccKZ''BB;OO<<[II88tVUZ\bccK SII+VVEEkRR  x44  v..ff hgr  c                    |                      |          }|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<   n@|dk    s|r8||d<   | 
                    ||          |d<   |                     |dd          |d<   |rs| 
                    ||          |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k    r|rd|d<   nd|d<   n|dk    r|rd
|d<   nd|d<   d}|                     d|d           \  }}||d!<   |                     |d"          }||                     |d"          }||d#<   |                     |d$d          }|                     |g d%          }| 	                    |          |d$<   |                     ||          S )&a  
         * @ignore
        create a trade order
        :see: https://developer-pro.bitmart.com/en/futures/#submit-order-signed
        :see: https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market', 'limit' or 'trailing'
        :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 fullfilled, 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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r/   )r9  r  r  r  moderi  N
reduceOnlyr   r~  r   r  GTCr   FOKr(  r  trailingTriggerPricer  trailingPercentcallback_raterL  trailingactivation_price_typeexecutive_pricer  
price_typer  	price_wayr  r  rK   cross	open_typer  r  rR  )r  r  r  rR  r  r  r  r  )ri  intamount_to_precisionr/  r  r  handle_post_onlyr   r  number_to_stringprice_to_precisionrC  r0  r  )r  r9  r  r  rK  rL  r   ri  r  r  r  isMarketOrderr  r  isExchangeSpecificPor}  isLimitOrderr  r  r  r  isTrailingPercentOrderrF  r  rR  s                            r  r  z!bitmart.create_swap_order_request  s   0 V$$Tl00@@AA
 

 &&v}==  00(__V\::
 $	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'6GO$*.*A*A&J^*_*_G&'/3/@/@I`bc/d/dG+, 	-)-)@)@)O)OG%&'+'>'>v|'T'TGO$$($5$5flA$N$NGL!u}} -+,GK((+,GK(( -+,GK((+,GK(5== $"#"#V^^ $"#"#
!??vW^__
F)((AA$YYv77F)6G%&$$VZ;;6  $a  $a  $a  b  b"33H==
{{7F+++r  c                 v   |                      |          }|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|}|r4|                     ||          |d<   |                     ||          |d<   n|r|dk    r| 	                    |dd          }|                     |d          }d}| 
                    |ddd          \  }}|rn||t          | j        dz             |                     |          }|                     |          }|                     t          j        ||                    }n||n|}|                     |t           |d         d         | j                  |d<   n|dk    r|                     ||          |d<   |rd	|d<   |rd|d<   |                     ||          S )aN  
         * @ignore
        create a spot order request
        :see: https://developer-pro.bitmart.com/en/spot/#place-spot-order
        :see: https://developer-pro.bitmart.com/en/spot/#place-margin-order
        :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 fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated'
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r/   )r9  r  r  r  r  zE createOrder() only accepts timeInForce parameter values of IOC or POr  ri  Nr{  r   r  r~  r}  r  r  rL  r  rS  r  TrK   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  )ri  r/  r!   r/   r  r  r0  r  r  r  r)  r  r  r+   r  decimal_to_precisionr)   r   r  )r  r9  r  r  rK  rL  r   ri  r  r  r  r  r  r  r}  r  r  r  amountStringr  s                       r  r  z!bitmart.create_spot_order_requestT	  s    V$$Tl
 

 &&v}==%tw)ppqqq  00( $ 5E41900@TV\]]&6M:#>??u$8$%-;H; 	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 JH,<*47  6w  ,w  x  x  x'+'<'<V'D'D&*&;&;E&B&B#'#4#4W5GVa5b5b#c#c*2*:vvH&*&?&?(TZ[fTghoTprv  sE  'F  'F
##"&":":66"J"J 	,+GFO 	$#GFO{{7F+++r  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|                     |dd          }|||d<   nt          |          |d<   |                     |dg          }d}|d         r*|                     |                     ||                    }n| 	                    |d	d
          }|                     |d	d
g          }|s*| 
                    |                     ||                    }n)|                     |                     ||                    }|d         r|S |                     |d          }	|	du r|                     ||          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          S )aD  
        cancels an open order
        :see: https://developer-pro.bitmart.com/en/futures/#cancel-order-signed
        :see: https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
        :see: https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
        :see: https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: *spot only* the client order id of the order to cancel
        :param boolean [params.stop]: *swap only* whether the order is a stop order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr9  r/   r  r  r  r>   stoptriggerr@   r  Tsucceedr   z  cancelOrder() failed to cancel z
 order id rg  z cancelOrder() z is filled or canceled)r   r/   r  ri  r  r  r0  privatePostSpotV3CancelOrderr  safe_value_2%privatePostContractPrivateCancelOrder)privatePostContractPrivateCancelPlanOrderr  r  r/  r!   )r  r/   r9  r   ri  r  r  r!  r  r  	succeededrg  r  s                r  cancel_orderzbitmart.cancel_order	  sw    >#DG.Y$YZZZV$$fTl
 **6?DUVV$)6G%&&"%b''GJ6O#455&> 	h88Wf9U9UVVHH$$VVY??DYYv	':;;F hEEdkkRY[aFbFbccII$++V]_eJfJfgg0 &> 	Ox004<<##B///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  V,,{{54*---r  c                    |                                   i }d}| |                     |          }|d         |d<   d}d}|                     d||          \  }}|dk    r*|                     |                     ||                    }nH|dk    rB|t          | j        dz             |                     |                     ||                    }|S )a  
        cancel all open orders in a market
        :see: https://developer-pro.bitmart.com/en/spot/#cancel-all-orders
        :see: https://developer-pro.bitmart.com/en/futures/#cancel-all-orders-signed
        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.side]: *spot only* 'buy' or 'sell'
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr/   r9  rE   r>   r@   z- cancelAllOrders() requires a symbol argument)r  ri  r  privatePostSpotV1CancelOrdersr  r   r/   &privatePostContractPrivateCancelOrders)r  r9  r   r  ri  r!  r  s          r  cancel_all_orderszbitmart.cancel_all_orders	  s     	[[((F &tGH99:KVU[\\f6>>99$++gv:V:VWWHHV^^~'2a(abbbBB4;;wX^C_C_``H& r  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 argumentr>   z( fetchOrdersByStatus() does not support r  r  r/   r   d   )r9  offsetNr  	   r'  r  r   r     r  orders)
r   r/   r  ri  r#   privateGetSpotV3Ordersr  r  r  parse_orders)r  r'  r9  r
  r  r   ri  r  r!  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: x44h33  >>>r  c                 2   |                                   d}i }| |                     |          }|d         |d<   |||d<   d}d}|                     d||          \  }}|dk    rd}	|                     d|          \  }	}|	dk    rd|d	<   |||d
<   |                     |dd          }
|
|                     |dg          }|
|d<   |                     |                     ||                    }n|dk    r|                     |dd          }|                     |ddg          }|r*| 	                    |                     ||                    }n| 
                    |dd          }|                     |d          }|                     |ddg          }|rd}|||d<   |                     |                     ||                    }nt          | j        dz   |z   dz             |                     |dg           }|                     ||||          S )a  
        :see: https://developer-pro.bitmart.com/en/spot/#current-open-orders-v4-signed
        :see: https://developer-pro.bitmart.com/en/futures/#get-all-open-orders-keyed
        :see: https://developer-pro.bitmart.com/en/futures/#get-all-current-plan-orders-keyed
        fetch all unfilled currently open orders
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.marginMode]: *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders(only isolated margin orders are supported)
        :param int [params.until]: *spot* the latest time in ms to fetch orders for
        :param str [params.type]: *swap* order type, 'limit' or 'market'
        :param str [params.order_state]: *swap* the order state, 'all' or 'partially_filled', default is 'all'
        :param str [params.orderType]: *swap only* 'limit', 'market', or 'trailing'
        :param boolean [params.trailing]: *swap only* set to True if you want to fetch trailing orders
        :param boolean [params.trigger]: *swap only* set to True if you want to fetch trigger orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr/   r9  r  ro   r>   r>  r?  r@  rA  r<  r=  r@   r  r  r  Fr  r  z$ fetchOpenOrders() does not support rB  r  )r  ri  r  rC  r  r0   privatePostSpotV4QueryOpenOrdersr  r  )privateGetContractPrivateCurrentPlanOrderrk  r/  &privateGetContractPrivateGetOpenOrdersr#   r/   r  r  )r  r9  r
  r  r   ri  r  r  r!  rF  r<  isStopr  r  r  s                  r  fetch_open_orderszbitmart.fetch_open_orders@
  sx   & 	[[((F &tGH$GG99:KVU[\\f6>>J!%!C!CDUW]!^!^JZ'''3$ ',$''CCE 6I;77%*	"<<T[[RX=Y=YZZHHV^^&&vvyAAFYYv	':;;F 
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}|                     d|          \  }}|dk    rd|d	<   |dk    rd
nd}	||||	<   |dk    rdnd}
|                     |d|
          }||                     |dg          }|||
<   d}|dk    r*|                     | 	                    ||                    }n)| 
                    | 	                    ||                    }|                     |dg           }|                     ||||          S )a?  
        :see: https://developer-pro.bitmart.com/en/spot/#account-orders-v4-signed
        :see: https://developer-pro.bitmart.com/en/futures/#get-order-history-keyed
        fetches information on multiple closed orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest entry
        :param str [params.marginMode]: *spot only* 'cross' or 'isolated', for margin trading
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr/   r9  rV   r>   z/ fetchClosedOrders() requires a symbol argumentr>  r?  r@  rA  r(  r=  r+  r<  r  )r  ri  r  r   r/   rC  r  r0  #privatePostSpotV4QueryHistoryOrdersr  %privateGetContractPrivateOrderHistoryr  r  )r  r9  r
  r  r   ri  r  r  rF  startTimeKey
endTimeKeyr<  r!  r  s                 r  fetch_closed_orderszbitmart.fetch_closed_orders
  s    	[[((F &tGH99:MvW]^^f6>>~'2c(cddd
!??@SU[\\
F###/GK '+v~~{{L$)GL!#'6>>YY

##FGZ@@YYvy11F"'GJ6>>??GU[@\@\]]HH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  )r  )r  r9  r
  r  r   s        r  fetch_canceled_orderszbitmart.fetch_canceled_orders
  s      **:vueVTTTr  c                 8   |                                   i }d}d}d}||                     |          }|                     d||          \  }}|dk    rs|                     |d          }|s||d<   |*|                     |                     ||                    }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
        :see: https://developer-pro.bitmart.com/en/spot/#query-order-by-id-v4-signed
        :see: https://developer-pro.bitmart.com/en/spot/#query-order-by-clientorderid-v4-signed
        :see: https://developer-pro.bitmart.com/en/futures/#get-order-detail-keyed
        :param str id: the id of the order
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: *spot* fetch the order by client order id instead of order id
        :param str [params.orderType]: *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
        :param boolean [params.trailing]: *swap only* set to True if you want to fetch a trailing order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nrp   r>   r  r  r@   z( fetchOrder() requires a symbol argumentr  Fr  r  r/   r9  r  r  )r  ri  r  r/  !privatePostSpotV4QueryClientOrderr  privatePostSpotV4QueryOrderr   r/   rk  r0  privateGetContractPrivateOrderr  r  )r  r/   r9  r   r  r  ri  r!  r  r  r  r  s               r  fetch_orderzbitmart.fetch_order
  s    	[[((F99,PVWWf6>> ,,V_EEM  (%'	"(AA$++gW]B^B^__;;DKKQW<X<XYYV^^~'2\(\]]]~~fj%@@H((==IYYvZ'@AAF '&	$"+ &tGH"$GJ::4;;wPV;W;WXXHf ~~h33f---r  c                 h   |                                   |                     |          }d|d         i}|dk    r|                     | j        d          }|                     ||          }|                     | j        di           }|                     |d|          }|                     |||          }|'|d         dz   |z   |d<   |                     |d          }|                     |                     ||                    }	| 	                    |	d	i           }
| 
                    |
|          S )
a  
        fetch the deposit address for a currency associated with self account
        :see: 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>`
        r  r/   r  r  r  networkN-r  )r  r  r  r  safe_string_upperr/  r0  !privateGetAccountV1DepositAddressr  r  parse_deposit_address)r  r  r   r  r  r  r  r  networkInnerr!  r  s              r  fetch_deposit_addresszbitmart.fetch_deposit_addressJ  s2    	==&&
 6>>"oodl<MNNO!33OTJJNt|ZDDH11&)^TTL++HlLQQL'&-j&9C&?,&N
#695599$++gv:V:VWW ~~h33))$999r  c                    |                      |d          }|                      |d          }|                      |d          }d }|                     ||          }|S|                    d          }t          |          }|                      ||dz
            }	|                     |	|          }|                     |           ||                      |d          ||                      |d          |dS )	Nr  addresschainr  r   r  address_memo)r.  r  r  tagr  )r/  safe_currencysplitra  safe_network_codecheck_address)
r  depositAddressr  r`  r  r  r  partspartsLength	networkIds
             r  r
  zbitmart.parse_deposit_addressq  s     %%njAA
"">9==  99%%j(;;KK$$Ee**K((a@@I,,YAAG7###"((6::##NNCC
 
 	
r  c                     |                      |d          }||k    r|                      |d          }|S |                     |          S )Nr0   r  )r/  network_id_to_code)r  r  r  r0   r  s        r  r  zbitmart.safe_network_code  sP    &11##Hf55DK&&y111r  c                 
   |                      ||          \  }}|                     |           |                                  |                     |          }|d         |d|d}|||d<   |dk    r|                     | j        d          }|                     ||          }	|                     | j        di           }
|                     |d	|	          }|                     |
||          }|'|d
         dz   |z   |d
<   |                     |d	          }| 	                    | 
                    ||                    }|                     |d          }|                     ||          }| 
                    ||||d          S )a  
        make a withdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r/   zTo Digital Address)r  rK  destinationr  Nr  r  r  r  r  r  r  r  )r  r  r  )handle_withdraw_tag_and_paramsr  r  r  r  r  r  r/  r0  !privatePostAccountV1WithdrawApplyr  parse_transaction)r  r  rK  r  r  r   r  r  r  r  r  r  r!  r  transactions                  r  r   zbitmart.withdraw  s    99#vFFV7###==&& /	
 
 ?&)GN#6>>"oodl<MNNO!33OTJJNt|ZDDH,,VYOOG&&x'BBG"&-j&9C&?'&I
#695599$++gv:V:VWW x00,,T8<<{{;)
 )
   	r  c                    |                                   |d}|d|d}d }| |                     |          }|d         |d<   |dk    r|                     | j        d          }|                     ||          }	|                     | j        di           }
|                     |d	|	          }|                     |
||          }|4|dxx         d
|z   z  cc<   |d         |d<   |                     |d	          }|                     |                     ||                    }|                     |di           }| 	                    |dg           }| 
                    ||||          S )N2   r   )operation_typer  r  r/   r  r  r  r  r  r  r  r  records)r  r  r  r  r  r/  r0  )privateGetAccountV2DepositWithdrawHistoryr  r  parse_transactions)r  r  r  r
  r  r   r  r  r  r  r  r  r!  r  r%  s                  r  fetch_transactions_by_typez"bitmart.fetch_transactions_by_type  s   =E"
 

 }}T**H"*4.GJ6>>"oodl<MNNO!33OTJJNt|ZDDH,,VYOOG&&x'BBG"
###sW}4####*:#6 6955AA$++gW]B^B^__2 x44..y"55&&w%GGGr  c                 
   |                                   d|i}|                     |                     ||                    }|                     |di           }|                     |di           }|                     |          S )aH  
        fetch information on a deposit
        :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  r  r  r   r  r/   r  r   r  r!  r  r*  s           r  fetch_depositzbitmart.fetch_deposit       	"
 @@WV\A]A]^^. x44h33%%f---r  c                 4    |                      d||||          S )a  
        fetch all deposits made to an account
        :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  r
  r  r   s        r  fetch_depositszbitmart.fetch_deposits!  s      ..y$ufUUUr  c                 
   |                                   d|i}|                     |                     ||                    }|                     |di           }|                     |di           }|                     |          S )ag  
        fetch data on a currency withdrawal via the withdrawal id
        :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
        :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   r1  r2  s        r  fetch_withdrawalszbitmart.fetch_withdrawalsS  s      ..z4vVVVr  c                 B    ddddddd}|                      |||          S )Npendingr)  r  failed)r   r  r  r  r  r  r  r  r'  r  s      r  parse_transaction_statusz bitmart.parse_transaction_status^  s:    
 
 &&999r  c                    d }|                      |d          }|                      |d          }d }||dk    rd}|}n|
|dk    r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k    r|nd |dk    r|                     |          nd |dS )Nwithdraw_id
deposit_idr  r   r  arrival_amount
apply_timer  r'  r  r  tx_idr  r  r.  r/   rK  r  addressFrom	addressTor  tagFromtagTor  r,  txidinternalcommentr   )r  r  r  )r/  rd  r  rb  r<  r|  )r  r!  r  r/   
withdrawId	depositIdr  rK  r  r`  r  r'  feeCostr  rG  r  r  s                    r  r   zbitmart.parse_transactioni  sh   0 %%k=AA
$$[,??	"r)9)9DBB#)r//DB!!+/?@@%%k<@@	%%k:>>
&&z8<<..t/?/?X/V/VWW"";66  C W55"";	::{N;;
K
"
 
 f	

 t
 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
        :see: https://developer-pro.bitmart.com/en/spot/#margin-repay-isolated
        :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/   r9  r  rK  r  rK  r9  )r  ri  r  currency_to_precision$privatePostSpotV1MarginIsolatedRepayr  r  parse_margin_loanr  r9  r  rK  r   ri  r  r  r!  r  r!  s              r  repay_isolated_marginzbitmart.repay_isolated_margin  s     	V$$==&&Tl 00v>>
 

 <<T[[RX=Y=YZZ x44,,T8<<{{;)
 )
   	r  c                    |                                   |                     |          }|                     |          }|d         |d         |                     ||          d}|                     |                     ||                    }|                     |di           }	|                     |	|          }
|                     |
||d          S )a  
        create a loan to borrow margin
        :see: https://developer-pro.bitmart.com/en/spot/#margin-borrow-isolated
        :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/   rN  r  rO  )r  ri  r  rP  %privatePostSpotV1MarginIsolatedBorrowr  r  rR  rS  s              r  borrow_isolated_marginzbitmart.borrow_isolated_margin  s     	V$$==&&Tl 00v>>
 

 ==dkk'SY>Z>Z[[ x44,,T8<<{{;)
 )
   	r  c                 h    |                      |dd          |                     d |          d d d d |dS )N	borrow_idrepay_id)r/   r  rK  r9  r  r  r.  )r  rb  )r  r.  r  s      r  rR  zbitmart.parse_margin_loan  sJ     $$T;
CC//h??
 
 	
r  c                 n   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |dg           }|                     |d          }|                     ||          S )a  
        fetch the rate of interest to borrow a currency for margin trading
        :see: 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>`
        r9  r/   r  r8  r   )r  ri  #privateGetSpotV1MarginIsolatedPairsr  r  parse_isolated_borrow_rate)	r  r9  r   ri  r  r!  r  r8  
borrowRates	            r  fetch_isolated_borrow_ratez"bitmart.fetch_isolated_borrow_rate  s     	V$$fTl
 ;;DKKQW<X<XYYB x44//$	266__Wa00
..z6BBBr  c           
         |                      |d          }|                     ||          }|                     |di           }|                     |di           }|                      |d          }|                      |d          }||                     |          |                     |d          |                     |          |                     |d          dd d |d	S )Nr9  rB  rC  r  hourly_interesti6 )	r9  rB  baseRaterC  	quoteRateperiodr  r  r.  )r/  rV  r  rb  rd  )	r  r.  ri  r  r9  baseData	quoteDatarE  rF  s	            r  r]  z"bitmart.parse_isolated_borrow_rateD  s    0 ##D(33!!(F33??444OOD'266	!!(J77""9j99++F33((3DEE,,W55)))5FGG

 

 
	
r  c                 t   |                                   |                     |          }|                     |di           }|                     |dg           }g }t          dt	          |                    D ]@}|                     ||          }|                    |                     |                     A|S )a  
        fetch the borrow interest rates of all currencies, currently only works for isolated margin
        :see: 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  r8  r   )r  r\  r  r`  ra  re  r]  )r  r   r!  r  r8  rg  rh  r9  s           r  fetch_isolated_borrow_ratesz#bitmart.fetch_isolated_borrow_ratesn  s     	;;FCCB x44//$	266q#g,,'' 	C 	CA__Wa00FMM$99&AABBBBr  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
        :see: https://developer-pro.bitmart.com/en/spot/#margin-asset-transfer-signed
        :see: https://developer-pro.bitmart.com/en/futures/#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/   )rK  r  r>   r?   inr  r9  r@   spot_to_contractr  outcontract_to_spotz? transfer() requires either fromAccount or toAccount to be spotNr  r'  r  message)r  r  rP  convert_type_to_accountr   r/   'privatePostSpotV1MarginIsolatedTransferr  $privatePostAccountV1TransferContractr  parse_transferparse_transfer_statusr  )r  r  rK  ri  rj  r   r  amountToPrecisionr  fromIdtoIdr!  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 x44{{4..tX>>d001C1CHfV_1`1`aaA
   	r  c                 <    dddd}|                      |||          S )Nr)  )r   OKFINISHEDr  r;  s      r  ru  zbitmart.parse_transfer_status  s1    
 

 &&999r  c                 :    ddd}|                      |||          S )Nr>   r@   ro  rm  r  r  r  typess      r  parse_transfer_to_accountz!bitmart.parse_transfer_to_account  .     & &
 
 tT222r  c                 :    ddd}|                      |||          S )Nr@   r>   r}  r  r~  s      r  parse_transfer_from_accountz#bitmart.parse_transfer_from_account  r  r  c                    |                      |d          }|                     |d          }|                      |d          ||                     |          |                     ||          |                     |d          |                     |                      |d                    |                     |                      |d                    |                     |                      |d                    dS )Nr  r  transfer_idrK  r  r  )r/   r  r  r  rK  ri  rj  r'  )r/  r  r|  rb  rd  r  r  ru  )r  r   r  r`  r  s        r  rt  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                 B   |                                   |d}|                     |d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
        :see: https://developer-pro.bitmart.com/en/futures/#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  r  r/   r  
time_startr  r<  tilltime_endr  r%  )
r  r  r  r  r0  (privatePostAccountV1TransferContractListr  r  r  parse_transfers)r  r  r
  r  r   r  r  r<  r=  r!  r  r%  s               r  fetch_transferszbitmart.fetch_transfers!  sN    	=E%%ffa88
 
 }}T**H"*4.GJ$)GL!$GG##FGV<<##FJ>>6FG#455")GJ@@WV\A]A]^^( x44..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
        :see: https://developer-pro.bitmart.com/en/spot/#get-borrow-record-isolated
        :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 argumentr9  r/   r  r(  r  r%  )	r   r/   r  ri  *privateGetSpotV1MarginIsolatedBorrowRecordr  r  parse_borrow_interestsfilter_by_currency_since_limit)r  r  r9  r
  r  r   ri  r  r!  r  rowsri  s               r  fetch_borrow_interestzbitmart.fetch_borrow_interestY  s     >#DG.a$abbbV$$fTl
  GCL$)GL!BB4;;wX^C_C_``, x44tY33..tV<<228T5%PPPr  c           
         |                      |d          }|                     ||          }|                     |d          }|                      |d          d|                     |                      |d                    |                     |d          |                     |d          |                     |d          ||                     |          |d	S )	Nr9  r  r>  r  interest_amountra  borrow_amount)	r9  rF  r  ri  interestRateamountBorrowedr  r  r.  )r/  r  r  rb  rd  r|  )r  r.  ri  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 )an  
        Retrieves the open interest of a currency
        :see: https://developer-pro.bitmart.com/en/futures/#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:
        r&  z3 fetchOpenInterest() supports contract markets onlyr9  r/   r  )r  ri  r   r/   #publicGetContractPublicOpenInterestr  r  parse_open_interestrx  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  r9  open_interestopen_interest_value)r9  openInterestAmountopenInterestValuer  r  r.  )r  r/  safe_open_interestrV  rd  r|  )r  ri  ri  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  rR  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
        :see: https://developer-pro.bitmart.com/en/futures/#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   rF  r>  r  r@   z+ setLeverage() supports swap contracts onlyr/   )r9  rR  r  )
r   r/   rC  check_required_argumentr  ri  r   r  (privatePostContractPrivateSubmitLeverager  )r  rR  r9  r   rF  ri  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 )ar  
        fetch the current funding rate
        :see: https://developer-pro.bitmart.com/en/futures/#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>`
        r@   z0 fetchFundingRate() supports swap contracts onlyr9  r/   r  )r  ri  r   r/   "publicGetContractPublicFundingRater  r  parse_funding_raterx  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 x44&&tV444r  c                 b   |                      |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 S )Nr9  r  r.  	markPrice
indexPricer  estimatedSettlePricer  fundingRateexpected_ratefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRate
rate_valuepreviousFundingTimestamppreviousFundingDatetime)r/  r  rV  r|  rd  )r  r&  ri  r  r  s        r  r  zbitmart.parse_funding_rate  s<    ##Hh77%%h<<	
H
d&&x88
 
 $	

 D
 #D
 
 Y//
 4++HoFF
 
 t
 t
 #D
 "4
 "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
        :see: https://developer-pro.bitmart.com/en/futures/#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>`
        r9  r/   r  r   )r  ri  !privateGetContractPrivatePositionr  r  r  parse_position)r  r9  r   ri  r  r!  r  firsts           r  fetch_positionzbitmart.fetch_position3  s     	V$$fTl
 99$++gv:V:VWW< x44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
        :see: https://developer-pro.bitmart.com/en/futures/#get-current-position-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/   r9  r  F)r  ra  r/  ri  r  r  r  r`  re  r  r  filter_by_array_positions)r  r8  r   ri  symbolsLengthr  r  r!  	positionsrg  rh  s              r  fetch_positionszbitmart.fetch_positionsb  s%    	LLM$$Wa00E[[''FA &tGH99$++gv:V:VWW< OOHfb99	q#i..)) 	= 	=AMM$--il;;<<<<%%g..--fhOOOr  c                 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 )Nr9  r  position_typemaintenance_margincurrent_valueposition_crossr.  r/   r  lastUpdateTimestamphedgedr  r   longshort	contractscurrent_amountrW  
entryPriceentry_pricer  
mark_price	lastPricer  rR  
collateralinitialMarginunrealized_valuerealized_value)initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentageunrealizedPnlrealizedPnlliquidationPricerF  r   marginRatiostopLossPricetakeProfitPrice)	r/  r  r  r+   
string_divsafe_positionr|  rd  r  )r  positionri  r  r9  r  r  r  r  r  r  r  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 )a|  
        retrieves the users liquidated positions
        :see: https://developer-pro.bitmart.com/en/futures/#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 argumentr@   z1 fetchMyLiquidations() supports swap markets onlyr9  r/   r(  r+  r  r   r  	liquidate)r   r/   r  ri  r#   r,  r  r  r  r`  ra  r/  re  parse_liquidations)r  r9  r
  r  r   ri  r  r!  r  rg  rh  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 x44q#d))$$ 	% 	%AGE#//v>>;..e$$$&&vvueDDDr  c                 |   |                      |d          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }t          j        ||          }t          j        ||          }	|                     ||                     ||          |                     |          |                     |          |                     |          |                     |          |                     |	          ||                     |          d	          S )Nr9  r  r  rW  r  )	r.  r9  r  rW  rL  	baseValue
quoteValuer  r  )r/  r  r+   r  safe_liquidationrV  r  r|  )
r  liquidationri  r  r  contractsStringcontractSizeStringr  baseValueStringquoteValueStrings
             r  parse_liquidationzbitmart.parse_liquidation  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                 *    |                                  S N)r.  )r  s    r  noncezbitmart.nonce:  s      """r  r   GETc                    |                      | j        d         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   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)implode_hostnamer   implode_paramsr0  extract_params	urlencodecheck_required_credentialsr  r.  r/  r  r   jsonr   hmacencoder   hashlibsha256)r  pathr   r  r   r  r  baseUrlr   queryqueryStringgetOrDeleter  r  auth	signatures                   r  signzbitmart.sign=  s   ''	%(8(@AAmd11$???		&$"5"5d";";<<?Fh,> 	) )"nnU33s[(()++---D--//00I''jBSTTH K"+"* 2	 G  #yy''"s?TX-3kAD		$++d"3"3T[[5M5Mw~^^I#,GK fdwOOOr  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 )	Nrp  r)  successr  r    r  r  )safe_string_lowerr/  r/   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r  r  reasonr   r  r  r  r!  requestHeadersrequestBodyrp  isErrorMessage	errorCodeisErrorCodefeedbacks                  r  handle_errorszbitmart.handle_errorsY  s   4 ((9==!-_GtO_'U^J^$$Xv66	 ,G93F 	*. 	*w}t+H001I9V^___001I9V^___001I7T\]]]001I7T\]]])))tr  r  )g__name__
__module____qualname__r  r"  r6  rn  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   rH  rK  r   ra  rW  rq  r   ru  ry  r   r  r  r  floatr  r   r   r
   r  r  r  r  r  r  r  r  r  r  r  r
  r  r   r(  r.  r   r3  r5  r7  r<  r   rT  rW  rR  r_  r]  rh  r   r   ru  r  r  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__)r  s   @r  r-   r-   !   s       T
 T
 T
 T
 T
l !# 6 6 6 6( #% :
 :
 :
 :
x )+ ^ ^ ^ ^@ -/ g g g gR $& 1 1$v, 1 1 1 1 ') / /Z / / / /b 79 "
 "
# "
 "
 "
 "
H
 
 
 
 
 
, <> 5 5s 5 5 5 5:c c6 cV c c c cJ 02 Q1 Q13 Q1f Q1 Q1 Q1 Q1f 04B G GW G7 G G G G@ :>b GH GHs GH3 GHY GH GH GH GHRc c c5 c c c cJ 6:UW '? '?3 '?s '?# '?\`af\g '? '? '? '?R< < <4 < < < <| 26DW[df ZI ZI# ZIc ZIQT ZIkoptku ZI ZI ZI ZIx -1tRV_a e= e=c e= e=C e= e= e= e=N 9=4^bkm ; ;S ;# ;S ;X[ ; ; ; ;&"-H "- "- "- "-H   $& {? {?( {? {? {? {?z
 
V 
?R 
 
 
 
& 57 , , ,;N , , , ,<{ { {5 { { { {z3 3 3: : :2 RT N N N5 N N N N  gksu B B3 Bi By BRW B`c B B B BH tx  AC \, \, \,9 \,I \,_d \,mp \, \, \, \,| tx  AC ;, ;, ;,9 ;,I ;,_d ;,mp ;, ;, ;, ;,z 37r K. K.s K.C K. K. K. K.Z /32 + + + + + +Z <@daenp 3? 3?S 3? 3?[^ 3? 3? 3? 3?j /3TXac q= q= q=3 q=c q=hlmrhs q= q= q= q=f 154VZce *= *=# *=S *=PS *=jnotju *= *= *= *=X 37TX\eg 	U 	UC 	Us 	URU 	U 	U 	U 	U 26b ^. ^.c ^.3 ^. ^. ^. ^.@ 79 %: %:# %: %: %: %:N
 
 
 
82 2 2 2 ?C2 0 0S 0% 0 0 0 0d <@daenp 2H 2HS 2H 2H[^ 2H 2H 2H 2Hh 26b %. %. %.3 %. %. %. %.N *.Dt\^ 	V 	V3 	Vc 	V 	Vcghsct 	V 	V 	V 	V 59 %. %.3 %.c %. %. %. %.N -1tRV_a 	W 	Wc 	W 	WC 	Wfjkvfw 	W 	W 	W 	W	: 	: 	:F
 F
x F
; F
 F
 F
 F
P LN " "C "s " " " "H TV " "S " "U " " " "H
 
 
 
 
 
0 >@ 1C 1C 1C 1C 1C 1Cf(
 (
v (
 (
 (
 (
T 24 / / / /b [] C CS C% Cc Cc Can C C C CJ: : :3 3 33 3 3%
 %
 %
 %
 %
 %
N +/TPT]_ 6E 6EC 6Es 6E# 6E 6E 6E 6Ep 15DW[jnwy /Q /Q# /Qc /QQT /Qdg /Q /Q /Q /Qb
 
& 
 
 
 
8 79 6 6# 6 6 6 6@ F    ( 9=R [ [S [# [ [ [ [4 68 5 5 5 5 5 5@
 
6 
 
 
 
> 24 -2 -2S -2 -2 -2 -2^ 26b 6P 6Pw 6P 6P 6P 6Pp> >v > > > >@ 37TX\eg 8E 8EC 8Es 8ERU 8E 8E 8E 8Et$ $V $ $ $ $L# # # &eBSW P P P P8      r  r-   )2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   typingr   ccxt.base.errorsr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   ccxt.base.decimal_to_precisionr)   r*   ccxt.base.preciser+   r-    r  r  <module>r+     s   ( ' ' ' ' ' - - - - - -  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 * * * * * * ) ) ) ) ) ) 3 3 3 3 3 3 4 4 4 4 4 4 % % % % % %RA RA RA RA RAh RA RA RA RA RAr  