
    E#i                       S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"  S SK#J$r$  S SK%J&r&  S SK%J'r'  S SK%J(r(  S S	K%J)r)  S S
K%J*r*  S SK%J+r+  S SK%J,r,  S SK%J-r-  S SK%J.r.  S SK%J/r/  S SK%J0r0  S SK%J1r1  S SK%J2r2  S SK%J3r3  S SK%J4r4  S SK%J5r5  S SK%J6r6  S SK7J8r8  S SK7J9r9  S SK:J;r;   " S S\\5      r<g)    )Exchange)ImplicitAPIN)AnyBalancesBorrowInterest
CurrenciesCurrencyDepositAddressFundingHistoryIntIsolatedBorrowRateIsolatedBorrowRatesLedgerEntryMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTransactionMarketInterfaceTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)NetworkError)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)TRUNCATE)	TICK_SIZE)Precisec                   	  ^  \ rS rSrS\4U 4S jjr0 4S\4S jjr0 4S jr0 4S\	\
   4S jjr0 4S\	\
   4S jjr0 4S\	\   4S jjr0 4S\4S	 jjrS
\S\S\4S jr0 4S\4S jjrSS\4S jjr0 4S\4S jjrSS\S\S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjrS0 4S\S\S\4S jjr SS\S\S\!4S jjr"SS0 4S\S\S\S\	\!   4S jjr#SS\S\$4S  jjr%S!SS0 4S\S"\S\S\S\	\$   4
S# jjr&SSS0 4S\S\S\4S$ jjr'SSS0 4S%\S\S\S\4S& jjr(S\)4S' jr*S( r+0 4S\)4S) jjr,SS*\S\S\-4S+ jjr.0 4S\S\-4S, jjr/SS-\S\S\04S. jjr1S/ r2S0 r30 4S\S1\44S2 jjr5S0 4S\S3\6S4\7S5\4S6\84
S7 jjr90 4S8\	\:   4S9 jjr;S0 4S\S3\6S4\7S5\4S6\84
S: jjr<S0 4S\S3\6S4\7S5\4S6\84
S; jjr=S0 4S%\S\4S< jjr>S0 4S=\	\   S\S\	\0   4S> jjr?S0 4S\4S? jjr@SSS0 4S\S\S\4S@ jjrASSS0 4S\S\S\S\	\0   4SA jjrBSSS0 4S\S\S\S\	\0   4SB jjrCSSS0 4S\S\S\4SC jjrDS0 4S%\S\4SD jjrE0 4S\S\F4SE jjrGSS\F4SF jjrHS0 4S\S5\4SG\SH\S\I4
SI jjrJSSS0 4S\S\S\4SJ jjrKS0 4S%\S\4SK jjrLSSS0 4S\S\S\S\	\I   4SL jjrMS0 4S%\S\4SM jjrNSSS0 4S\S\S\S\	\I   4SN jjrOSO\4SP jrPSSQ\S\S\I4SR jjrQ0 4S\S\4SS jjrR0 4S\S\S5\44ST jjrSSS\4SU jjrT0 4S\S\U4SV jjrVSSW\S\S\U4SX jjrW0 4S\X4SY jjrY0 4S\S5\4SZ\S[\S\Z4
S\ jjr[SO\S\4S] jr\S^ r]S_ r^SS`\S\S\Z4Sa jjr_SSS0 4S\S\S\S\	\Z   4Sb jjr`SSSS0 4S\S\S\S\S\	\a   4
Sc jjrbSSW\S\S\a4Sd jjrc0 4S\4Se jjrdSS\4Sf jjreS0 4Sg\fS\4Sh jjrg0 4S\S\h4Si jjriSSS0 4S\S\S\4Sj jjrjSS\S\h4Sk jjrk0 4S\4Sl jjrlS0 4S\S\	\m   4Sm jjrnSSn\S\4So jjroSSS0 4S\S\S\4Sp jjrpSS\4Sq jjrqSS0 4S%\S\S3\6S4\7S5\8S6\8S\04Sr jjrrSSS0 4S\S\S\S\	\s   4Ss jjrtSSt\S\S\s4Su jjruSv rvSSSS0 4Sw\S\S\S\4Sx jjrwSSS0 4S\S\S\S\	\x   4Sy jjrySS\4Sz jjrzSS\S\S\	\x   4S{ jjr{SS0 4S\4S| jjr|S0 4S}\}S\4S~ jjr~S0 4S\4S jjrS rSS0 SS4S jrS\fS\S\S\S\S\4S jrSrU =r$ )bitmart!   returnc                   > U R                  [        [        U ]  5       0 SS_SS_S/ SQ_SS_S	S
_SS_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_0 S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_E0 S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_E0 SCS_SDS_SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_E0 STS_SUS_SVS_SWS_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_E_SeSf_SgShSiSjSk.SlSmSnSoSp.SqSr._SsSSSSt._SuSv0 SwSx_SySx_SzS{_S|S{_S}S~_SS_SS_SS~_SS_SS_SS_SS~_SS_SS~_SS_SS_SS~_S~SS~S~SSSSSS~S.
E00 SS{_SS{_SS~_SS{_SS~_SS{_SS{_SS~_SS_SS~_SS_SS_SS{_SS{_SS_SS_SS~_0 SS~_SS_SS~_SS_SS_SS_SS_SS~_SS_SS_SS_SS~_SS_SS_SS_SS_SS_ESSSSSSSS.E0 SS_SS_SS_SS_SS_SS{_SS{_SS{_SS{_SS_SS_SS_SS_SS_SS_SS~_SS~_0 SS~_SS~_SSx_SS_SSx_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_ESSSSSSSSSSSS.ES.S._SSSxS~SSSSSSSSSSS._SSSSU R	                  S5      U R	                  S5      U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      //U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  GS 5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  GS5      /U R	                  S5      U R	                  GS5      /U R	                  S5      U R	                  GS5      //GS.GS.0_GS[
        _GS0 GS[        _GS	[        _GS
[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS [        _GS![        _GS"[        _GS#[        _GS$[        _GS%[        _GS&[        _GS'[        _GS([        _GS)[        _E0 GS*[        _GS+[        _GS,[        _GS-[        _GS.[        _GS/[        _GS0[        _GS1[        _GS2[        _GS3[        _GS4[        _GS5[        _GS6[         _GS7[        _GS8[        _GS9[        _GS:[        _E0 GS;["        _GS<[$        _GS=[        _GS>[        _GS?[        _GS@[        _GSA[        _S[        _GSB["        _GSC[        _GSD[        _GSE[        _GSF[&        _GSG[(        _GSH[(        _GSI[(        _GSJ[(        _E0 GSK[(        _GSL[(        _GSM[(        _GSN[(        _GSO[        _GSP[        _GSQ[        _GSR[        _GSS[        _GST[        _GSU[        _GSV[        _GSW[        _GSX["        _GSY[        _GSZ[        _GS[[        _E0 GS\[        _GS][        _GS^[(        _GS_[&        _GS`[&        _GSa[&        _GSb[(        _GSc[(        _GSd[(        _GSe[        _GSf[        _GSg[        _GSh[        _GSi["        _GSj[        _GSk[        _GSl["        _E0 GSm[        _GSn[        _GSo[        _GSp[        _GSq[(        _GSr[(        _GSs[        _GSt[        _GSu[(        _GSv[(        _GSw[(        _GSx[(        _GSy[(        _GSz[(        _GS{[(        _GS|[        _GS}[        _E0 GS~[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[*        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS["        _GS["        _GS[(        _GS[(        _GS[(        _GS[        _GS[(        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[(        _GS[(        _GS[(        _GS[(        _GS[(        _GS["        _GS[&        _GS[(        _GS[&        _GS[        _GS[        _GS[(        _GS[(        _GS[(        _E[(        [(        [(        [        [        [(        [(        [(        GS.E[        [        GS.GS._GSGSGSGSGSGSGSGSGSGS._GSGSGSGS.GSS0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GS GS _GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GS	GS	_GS
GS
_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GS GS _GS!GS!_GS"GS"_GS#GS#_GS$GS%_GS&GS'_GS(GS(_GS)GS)_GS*GS*_GS+GS+_GS,GS,_GS-GS-_EGS.GS/GS0GS1GS2GS3GS4GS5GS6GS7GS8GS9GS:GS;GS<.EGSGSGSGSGS=.SGS>S0SSSk.SGS?GS@.
SSSS SSSS SSSSGSA.SSSSSSSGSB.GSCS0SGSDS GSESGSF.SSSSGSG.SGSDSSSGSH.S SGSDS S S SSSGSI.GSJGSK0GSL.	GSMSSSSSGSN.SSSSSSGSN.SGSO.SSSSGSA.SSSSGSP.SS S GSEGSQ.SSSGSR.SGSSSSGST.SGSDS S S SSGSU.GSJGSV0GSW.GSXGSM0GSXGSY0GSXGSY0GSZ.S S GSZ.GS[.GS\.E5      $ (]  Nidr8   nameBitMart	countries)USCNHKKR	rateLimitgQ@@versionv2	certifiedTprohasCORSspotmarginswapfutureFoptionborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTrailingPercentOrderfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLiquidationsfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransferfetchTransfersfetchWithdrawAddressesfetchWithdrawAddressesByNetworkfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModesetPositionModetransferwithdrawhostnamezbitmart.comurlszOhttps://github.com/user-attachments/assets/0623e9c4-f50e-48c9-82bd-65c3908c3a14zhttps://api-cloud.{hostname}zhttps://api-cloud-v2.{hostname}rK   rM   zhttps://www.bitmart.com/z"https://developer-pro.bitmart.com/z http://www.bitmart.com/?r=rQCFLhg333333?)urldiscountzhttps://www.bitmart.com/fee/en)logoapiwwwdocreferralfeesrequiredCredentials)apiKeysecretuidr   getzsystem/time   zsystem/servicezspot/v1/currenciesg      @zspot/v1/symbolszspot/v1/symbols/details   zspot/quotation/v3/tickers   zspot/quotation/v3/ticker   zspot/quotation/v3/lite-klineszspot/quotation/v3/klines   zspot/quotation/v3/bookszspot/quotation/v3/tradeszspot/v1/tickerzspot/v2/ticker   zspot/v1/ticker_detailzspot/v1/stepszspot/v1/symbols/klinezspot/v1/symbols/book   )
zspot/v1/symbols/tradeszcontract/v1/tickerszcontract/public/detailszcontract/public/depthzcontract/public/open-interestzcontract/public/funding-ratez$contract/public/funding-rate-historyzcontract/public/klineaccount/v1/currencieszcontract/public/markprice-klinez$account/sub-account/v1/transfer-listz'account/sub-account/v1/transfer-historyz"account/sub-account/main/v1/walletz+account/sub-account/main/v1/subaccount-listz+account/contract/sub-account/main/v1/walletz2account/contract/sub-account/main/v1/transfer-listz0account/contract/sub-account/v1/transfer-historyzaccount/v1/walletr   zspot/v1/walletzaccount/v1/deposit/addresszaccount/v1/withdraw/charge    z#account/v2/deposit-withdraw/historyz"account/v1/deposit-withdraw/detailz account/v1/withdraw/address/listzspot/v1/order_detail   zspot/v2/orderszspot/v1/tradeszspot/v2/tradeszspot/v3/orderszspot/v2/order_detailz%spot/v1/margin/isolated/borrow_recordz$spot/v1/margin/isolated/repay_recordzspot/v1/margin/isolated/pairszspot/v1/margin/isolated/accountzspot/v1/trade_feezspot/v1/user_feezspot/v1/broker/rebatezcontract/private/assets-detailzcontract/private/orderg333333?zcontract/private/order-history
   zcontract/private/positionzcontract/private/position-v2z contract/private/get-open-orders)z#contract/private/current-plan-orderzcontract/private/tradeszcontract/private/position-riskz%contract/private/affilate/rebate-listz$contract/private/affilate/trade-listz$contract/private/transaction-historyz"contract/private/get-position-modez'account/sub-account/main/v1/sub-to-mainz&account/sub-account/sub/v1/sub-to-mainz'account/sub-account/main/v1/main-to-subz%account/sub-account/sub/v1/sub-to-subz&account/sub-account/main/v1/sub-to-subz0account/contract/sub-account/main/v1/sub-to-mainz0account/contract/sub-account/main/v1/main-to-subz/account/contract/sub-account/sub/v1/sub-to-mainzaccount/v1/withdraw/applyzspot/v1/submit_orderzspot/v1/batch_orderszspot/v2/cancel_orderzspot/v1/cancel_orderszspot/v4/query/orderzspot/v4/query/client-orderzspot/v4/query/open-orderszspot/v4/query/history-orderszspot/v4/query/tradeszspot/v4/query/order-tradeszspot/v4/cancel_orderszspot/v4/cancel_allZ   zspot/v4/batch_orderszspot/v3/cancel_orderzspot/v2/batch_orderszspot/v2/submit_orderzspot/v1/margin/submit_orderg      ?zspot/v1/margin/isolated/borrowzspot/v1/margin/isolated/repayz spot/v1/margin/isolated/transferz!account/v1/transfer-contract-list<   zaccount/v1/transfer-contractzcontract/private/submit-orderg      @zcontract/private/cancel-orderzcontract/private/cancel-orders)z"contract/private/submit-plan-orderz"contract/private/cancel-plan-orderz contract/private/submit-leveragez#contract/private/submit-tp-sl-orderz"contract/private/modify-plan-orderz)contract/private/modify-preset-plan-orderz#contract/private/modify-limit-orderz#contract/private/modify-tp-sl-orderz#contract/private/submit-trail-orderz#contract/private/cancel-trail-orderz"contract/private/set-position-mode)r   post)publicprivate
timeframes-   x         i  i`'  i  )1m3m5m15m30m45m1h2h3h4h1d1w1Mr   tradingz0.0040z0.00350z0.002010z0.1850z0.0016250z0.00141000z0.00125000z0.001025000z0.000850000z0.0006z0.001z0.0009z0.0007z0.0005z0.0004z0.0003)takermaker)	tierBased
percentager   r   tiersprecisionMode
exceptions300003000130002300033000430005300063000730008300103001130012300133001430016300173001830019600006000160002600036000460005600066000760008600096001060011600126002060021600226002660027600286002960030600316005060051610016100361004610056100661007610087000070001700027000371001710027100371004710055000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425100051001510025100351004510055100651007510085100951010510115101251013510145101552000520015200252003520045300053001530025300353005530065300753008530095301057001580015900159002590035900459005590065900759008590095901059011400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042)4004340044400454004640047400484004940050)z1You contract account available balance not enoughz1you contract account available balance not enough)exactbroadcommonCurrencies	GOLDMINERz	Step HeroPACBEYONDzGorilla DiamondGoldariozMVP CoinTruebit)z$GMz$HEROz$PACBPGDTGLDMVPTRUTRC20BTCERC20)USDTr  ETHr   SOLOMNIXLMEOSNEOBTMBCHLTCBSVXRPPLEXXCHNEARFIOSCRTIOTXALGOATOMDOTADADOGEXYMGLMRMOVRZILINJKSMZECNASPOLYGONMATICHRC20HECOXDCONELATCSPRCasperICPComputerXTZMINABEP20BSC_BNBTHETAAKTARCELOFILNULSETCDASHDGBBEP2GRINWAVESABBCACAQTUMTLOSKARDIAKardiaChainFUSETRC10FIROFTMFantomEVERKAVAHYDRAPLCUBRISEOPTIMISMREEFSYSVITESTXSXPBITCIXRDASTRASTARZENHORIZENLTOETHWETHFIOSTAPTONTEVMOSXMROASOSMOz
OMAX ChainDESOBFICOHOCSCHEQNODLXEMFRAERG)r  r  OASYSr  OMAXr  r  r  r  r  r  NEMr  ERGO)r  Ethereumr  BitcointypeCCXTxBitmart000)
defaultNetworkstimeDifferenceadjustForTimeDifferencenetworksnetworksByIddefaultTyper`   accountsByType!createMarketBuyOrderRequiresPricebrokerId)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingmarketBuyRequiresPricemarketBuyByCostleverageselfTradePreventionicebergmax   i )r1  limitdaysBack	untilDayssymbolRequired)r1  triggerr:  rE  )r1  rB  rF  r:  rE  )r1  rB  rC  daysBackCanceledrD  rF  r:  rE  rB    )	sandboxrX   rY   r|   r   r   r   re   r}   default)lastmarkindex)r3  price)r1  r2  r3  r4  r5  r6  r7  r8  r9  r:  r;  r<  )r1  rB  rC  rD  )r1  rF  r:  d   )r1  rB  rF  r:  )r1  rB  rC  rG  rD  rF  r:    )extendsrX   r|   r   r   re   r}   rQ  forDerivatives)linearinverse)rJ  rR  rK   rM   rN   )optionsfeatures)deep_extendsuperr8   describeparse_numberr5   r#   r$   r&   r%   r0   r1   r2   r(   r+   r*   r.   r)   r/   r-   r,   r3   )self	__class__s    F/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/bitmart.pyrY  bitmart.describe#   s   gt = ? LB
)LB
ILB
 1LB
 LB
 tLB
 LB
 4LB
  VVV $V 	V
 %V %V $UV 'V "4V tV V /V ,UV 0V tV  !V" &t#V$ (%V& ''V( ()V* "5+V, -d-V. /V0 &t1V2 +E3V4 )%5V6 &t7V8 $T9V: ';V< (=V> "4?V@ AVB &tCVD (EVF 1%GVH  IVJ *4KVL +EMVN &tOVP #DQVR *5SVT $UUVV *4WVX +DYVZ t[V\ $U]V^ "5_V` aVb !$cVd &teVf  gVh diVj $TkVl +EmVn "4oVp dqVr !$sVt uuVv #DwVx  yVz $T{V| !$}V~ tV@ tAVB CVD TEVF tGVH "4IVJ #EKVL &tMVN 'OVP  QVR !$SVT )$UVV 25WVX "4YVZ #D[V\ ]V^ #E_V` &taVb tcVd  eVf "4gVh DiVj DkVLB
B CLB
D i:= 2;= # 9ELB
` "$aLB
j  %q(! -c	
 *3 21 4Q 3A 8 3A 21 3A )! )" 0  (!" 0#$ /%& 34/134129;8:@B1213;<; D1>1 B31 =a	1
 Fs1 Fq1 Mc1 KC1 ,Q1 01 )!1 5b1 5b1 >s1  =c!1" ;B#1& /'1( )!)1* )!+1. )!/10 )!112 /316 @718 ?91: 8;1< :1=1> ,R?1@ +BA1D 0E1H 9!I1J 1#K1L 9"M1N 4RO1P 7Q1R ;CS1T @C35:<AC@B@B>?a1d4A24 A"4 B2	4
 @4 A"4 KC4 KC4 J34 4S4 /4 /4 /4  0!4" .q#4$ 5a%4& 4Q'4( 7)4* /+4, 5a-4. 0/40 -b142 /346 /748 /94: /;4> 6s?4@ 9"A4B 8C4D ;BE4H <RI4J 7K4L 8M4N 8O4P 9"Q4R ?B>A<??B>AEH?B?B?B?B>?g4ghEKkLB
B CLB
` !%"&!..x8!..x8 "..s3T5F5Fx5PQ!..t4d6G6G6OP!..t4d6G6G6QR!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..w79J9J89TU!..w79J9J89TU	" "..s3T5F5Fw5OP!..t4d6G6G6QR!..t4d6G6G6QR!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..w79J9J89TU!..w79J9J89TU	"aLB
\	 Y]	LB
^	 J]J 0J 0	J
 -J 0J 0J 0J 0J 0J -J 0J 0J .J 1J  ]!J" .#J$ Z%J& -'J* Z+J, Z-J. Z/J0 ]1J2 ]3J4 ]5J6 ]7J8 ^9J: .;J< ]=J> ]?J@ ^AJB ]CJD -EJF -GJH -IJJ -KJL -MJN -OJP -QJR ZSJT ZUJV ]WJX ]YJZ .[J\ Z]J^ Z_J` ZaJb \cJd ]eJf ]gJj ]kJl ZmJn YoJp \qJr ZsJt ZuJv ZwJx ZyJz Z{J~ ZJ@ YAJB ZCJD ZEJF ZGJH ]IJJ \KJL \MJN \OJP \QJR \SJT \UJV \WJX \YJZ Z[J\ Z]J^ Z_J` ZaJb ZcJd ]eJf .gJh ZiJj 1kJl YmJn ZoJp ZqJr ZsJt ZuJv ZwJx \yJz ]{J| ]}J~ ]J@ \AJD \EJF \GJH ]IJJ ZKJL ZMJN ZOJP YQJR ]SJT ZUJV YWJX ]YJZ ][J\ ]]J^ ._J` \aJb \cJd ZeJf ]gJh \iJj \kJl \mJn \oJp \qJr \sJt \uJv ZwJx ZyJz Z{J| Z}J~ ZJ@ -AJB -CJD -EJF -GJH -IJJ -KJL -MJN -OJP -QJR -SJT ZUJV ZWJX ]YJZ ][J\ ]]J^ ]_J` -aJb ]cJd ]eJf ]gJh ]iJj .kJl ]mJp ]qJr ]sJt ]uJv ]wJx ]yJz -{J| Z}J~ \J@ ZAJB ZCJD ZEJF ]GJH ]IJJ YKJL YMJN \OJP \QJR \SJT ]UJV \WJX ]YJZ ][J\ ]]J^ ]_J` ]aJb ]cJd .eJf -gJh \iJj \kJl \mJn \oJp \qJr YsJt ]uJv \wJx ]yJz Z{J| Z}J~ \J@ \AJB \CJD *))--)))SJX J[IZYP_	LB
@ "$(!! 	!ALB
X $ "$
 #$+0VWV5V 5V W	V FV 5V 5V 5V 5V 5V 5V 5V  5!V$ F%V& 5'V* F+V, 5-V. F/V0 F1V2 F3V4 F5V6 57V8 59V: F;V< 5=V> F?V@ FAVB 5CVD 5EVF 5GVH 5IVJ 5KVL wMVN VOVP 5QVR 5SVT 5UVV HWVX :YVZ 5[V\ F]V^ Y_V` WaVb 5cVd $eVf FgVh 5iVj FkVl 5mVn FoVp 5qVr FsVt FuVv WwVx FyVz 5{V| F}V~ 5VF FGVH mIVJ FKVL WMVN FOVP 8QVV FWVX FYVZ W[V\ F]V^ W_Vd 
eVf FgVh 5iVj FkVl 5mVn 5oVp WqVt 5uVv GwVx 9yVz 5{V| F}V~ FV@ FAVD 5EVH 5IVJ % ""("" ""  !eVp # '"$	!  &F! #"# 6:-]od  %&*(-,0,1).+06:#'#("&#(	( #($)27+/$(/4#()$. r% '+!$$(%**/& ',#($)*/	# '+!$#($)*/( $(&*!$$(,0%)#($)*/	*  #u=~  )&*(,$($(%*-
 -1)-+/ )-(,).1
 &+7 $(#'"&#(	( #($(26+/9"$H '+!%$(%*	& ',#($(# ',!$#'$)	( '+!$$(,0%)#($)*  #B#H y
 "#3 "#3 	 ##[QuLB
 L L	    c                 n    U R                  U5      nU R                  US0 5      nU R                  US5      $ )a/  
fetches the current integer timestamp in milliseconds from the exchange server

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
dataserver_time)publicGetSystemTime	safe_dictsafe_integer)r[  paramsresponsera  s       r]  
fetch_timebitmart.fetch_timer  s;     ++F3 ~~h3  }55r_  c                 $   U R                  U R                  S0 5      nU R                  U R                  S5      nU R                  USU5      nU R                  USU5      nU R                  US5      nU R	                  U5      nU R                  US0 5      nU R                  US/ 5      nU R                  US5      nUS:X  a  SnU R                  X5      n	S	n
S	nU	b/  U R                  U	S
5      nUS:X  a  Sn
OSn
U R                  U	S5      nU
S	US	US.$ )a6  
the latest known information on the availability of the exchange API

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
r   r)  r"  ra  serviceservice_typerM   contractNstatus   okmaintenanceend_time)rn  updatedetar   info)rd  rU  safe_stringomitpublicGetSystemService	safe_listindex_byre  )r[  rf  rU  r)  r"  rg  ra  servicesservicesByTyperk  rn  rt  
statusCodes                r]  fetch_statusbitmart.fetch_status  s(    ..}bA&&t||]C=566*..v64 ~~h3>>$	26x@6>D"">8**7H=JQ&''<
 	
r_  c                    U R                  U5      nU R                  US0 5      nU R                  US/ 5      n/ nU R                  S   n[	        S[        U5      5       GH  nXG   nU R                  US5      n	U R                  US5      n
U R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nUS	-   U-   nU R                  US
5      nU R                  US5      n[        R                  " UU5      nU R                  US5      nUR                  U R                  0 SU	_SU
_SU_SU_SU_SS _SU_SU_SS _SS_SS_SS_SS_SS_SS_SU R                  USS5      S:H  _S S_S S S S S S S US!   US"   UU R                  U R!                  U R                  US#5      5      5      S$.S S S%.UU R                  US&5      S%.S S S%.U R                  U5      S S%.S'.S US(.E5      5        GM     U$ ))Nra  symbolsr   r   symbol	symbol_idbase_currencyquote_currency/min_buy_amountmin_sell_amountbase_min_sizer<   	numericIdbasequotesettlebaseIdquoteIdsettleIdr"  rK   TrL   FrM   rN   rO   activern  trade_statusrm  r   r   price_max_precisionamountrN  minr@  base_max_sizer=  r  rN  costrS  rT  contractSizeexpiryexpiryDatetimestrike
optionTyper   r   	precisionlimitscreatedru  )publicGetSpotV1SymbolsDetailsrd  ry  r   rangelenrv  re  safe_currency_coder6   
string_maxsafe_numberappendsafe_market_structuresafe_string_lower_2rZ  parse_precision)r[  rf  rg  ra  r  resultr   imarketr<   r  r  r  r  r  r  
minBuyCostminSellCostminCostbaseMinSizes                       r]  fetch_spot_marketsbitmart.fetch_spot_markets  s   55f=6 ~~h3..y"5yy#q#g,'AZF!!&(3B))&+>I%%fo>F&&v/?@G**62D++G4ECZ%'F))&2BCJ**63DEK(([AG**6?CKMM$44 36b36Y36 &36 	36
 36 $36 &36 736 D36 36 36 %36 36 %36 %36  $2268^TXaa!36" E#36$  $"&"gg)!..t/C/CDDTDTU[]rDs/tu  $#!
  +#//H
  $#
  $009#$  e36 3 3 (B r_  c                    U R                  U5      nU R                  US0 5      nU R                  US/ 5      n/ nU R                  S   n[	        S[        U5      5       GH  nXG   nU R                  US5      n	U R                  US5      n
U R                  US5      nU R                  U
5      nU R                  U5      nSnU R                  U5      nUS	-   U-   S
-   U-   nU R                  US5      nUS:H  nUS:H  nU R                  US5      nU(       d  US:X  a  S nUR                  U R                  0 SU	_SS _SU_SU_SU_SU_SU
_SU_SU_SU(       a  SOS_SS_SS_SU_SU_SS_SU R                  US5      S:H  _S S!_S!SU R                  US"5      UU R                  U5      S S US#   US$   U R                  US%5      U R                  US&5      S'.U R                  US(5      U R                  US)5      S*.U R                  US+5      U R                  US,5      S*.S S S*.S S S*.S-.U R                  US.5      US/.E5      5        GM     U$ )0Nra  r  r   r   r  r  r  r  r  :product_typer   ro  expire_timestampr<   r  r  r  r  r  r  r  r"  rM   rN   rK   FrL   rO   r  rn  rm  Tcontract_sizer   r   vol_precisionprice_precisionr  min_leveragemax_leverager  
min_volume
max_volumer  open_timestampr  )publicGetContractPublicDetailsrd  ry  r   r  r  rv  r  re  r  r  safe_string_lowerr  iso8601)r[  rf  rg  ra  r  r  r   r  r  r<   r  r  r  r  r  r  r  productTypeisSwap	isFuturesr  s                        r]  fetch_contract_marketsbitmart.fetch_contract_markets+  s!   66v>P ~~h3..y"5yy#q#g,'AZF!!&(3B%%fo>F&&v/?@G**62D++G4EH,,X6FCZ%'#-6F++FNCK!Q&F$)I&&v/ABF&A+MM$44 36b36T36 &36 	36
 36 &36 &36 736 H36 &h36 36 %36 36 )36 %36  $00BiO!36" D#36$   $ 0 0 I "&,,v"6"gg"..vG!--f6GH  $//G#//G!
  $//E#//E
  $#
  $#$  ,,V5EFe36 3 3! (H r_  c                     U R                   S   (       a  U R                  5         U R                  U5      nU R                  U5      nU R	                  X#5      $ )aD  
retrieves data on all markets for bitmart

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r&  )rU  load_time_differencer  r  array_concat)r[  rf  rK   rm  s       r]  fetch_marketsbitmart.fetch_markets  sN     <<12%%'&&v...v6  00r_  c                    U R                  U5      nU R                  US0 5      nU R                  US/ 5      n0 n[        S[	        U5      5       GHX  nXF   nU R                  US5      nUn	U R                  US5      n
UR                  S5      S:  nU(       dH  UR                  S5      nU R                  US5      n	U R                  US5      nUb  UR                  5       n
U R                  U	5      nU R                  X^5      nUc&  UU	US	U R                  US
5      S	S	S	0 U(       a  SOSS.
nU R                  U
5      nU R                  US5      nU R                  US5      nUU
UUUU=(       a    UU R                  US5      U R                  US5      S	S.S	S	S.S.S.US   U'   XU'   GM[     [        UR                  5       5      n[        S[	        U5      5       H!  nUU   nUU   nU R                  U5      UU'   M#     U$ )z
fetches all available currencies on an exchange

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
ra  
currenciesr   currencynetworkNFT-r   Nr=   othercrypto)
ru  r<   coder  r=   depositr   r  r'  r"  withdraw_enableddeposit_enabledwithdraw_feewithdraw_minsizer  )r   r  )ru  r<   r  r   r  r  feer  r'  )publicGetAccountV1Currenciesrd  ry  r  r  rv  findsplitupperr  network_id_to_code	safe_boolr  listkeyssafe_currency_structure)r[  rf  rg  ra  r  r  r  r  fullId
currencyId	networkIdisNtfpartssecondcurrencyCodeentrynetworkCoder   r  r  keys                        r]  fetch_currenciesbitmart.fetch_currencies  s/    44V<2 ~~h3^^D,;
q#j/*A!}H%%h
;FJ((9=I[['1,ES)!--eQ7
))%3% &I22:>LNN68E}$$(!% ,,Xv># $" "',G( 11)<K~~h0BCHnnX/@AG #$"".w''.A  $//:LM#!
  $# 	.E*k*& $)< c +d FKKM"q#d)$Aq'Cc{H66x@F3K % r_  r  r  c                 *   Uc  U R                  U5      nU R                  U5      nUS   nS nU R                  US0 5      n0 nUcx  U R                  Xa5      nUc>  [        UR	                  5       5      n	[        U	5      n
U
S:  a  U R                  XiS   5      nU R                  US0 5      nU R                  US5      nOQU R                  Xb5      nUb&  U R                  US0 5      nU R                  US5      nOUSU R                  X!5      -   -  nUb  U$ U$ )Nr<   r'  r   ru  r  r  )	default_network_coder  rd  r  r  r  
safe_valuerv  network_code_to_id)r[  r  r  r  r<   idFromNetworkr'  networkInfor  r  lengthprovidedOrDefaultNetworks               r]  %get_currency_id_from_code_and_network-bitmart.get_currency_id_from_code_and_network  s   33LAK==.d^!>>(J;nnX<GHMMO,TA:"oohQ@G..&"=K ,,[*EM'+~~h'L$'3"nn-EvrR $ 0 0j IcD33KNNN!.!:}CCr_  r  c                    U R                  5         U R                  U5      nSnU R                  U5      u  pBSU R                  US   U5      0nU R	                  U R                  XR5      5      nUS   n0 nU R                  US5      X'   UU0 S.$ )aa  
@deprecated
       please use fetchDepositWithdrawFee instead
       :param str code: unified currency code
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param str [params.network]: the network code of the currency
       :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
       Nr  r  ra  r  )ru  r   r  )load_marketsr  handle_network_code_and_paramsr  !privateGetAccountV1WithdrawChargeextendr  )	r[  r  rf  r  r  requestrg  ra  withdrawFeess	            r]  fetch_transaction_feebitmart.fetch_transaction_fee(  s     	==&==fEBB8FCSU\]
 99$++g:VW !--dNC$
 	
r_  Nr  c                 <    UU R                  US5      S S.S S S.0 S.$ )Nr  )r  r   )ru  r   r  r'  )r  )r[  r  r  s      r]  parse_deposit_withdraw_fee"bitmart.parse_deposit_withdraw_feeO  s;     ''^<"
 " 
 	
r_  c                     U R                  5         SnU R                  U5      u  p2SU R                  X5      0nU R                  U R	                  XB5      5      nUS   nU R                  U5      $ )am  
fetch the fee for deposits and withdrawals

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

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: the network code of the currency
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
Nr  ra  )r  r   r  r  r  r  )r[  r  rf  r  r  rg  ra  s          r]  fetch_deposit_withdraw_fee"bitmart.fetch_deposit_withdraw_feee  sv     	==fEBB4Q
 99$++g:VW ..t44r_  tickerr  c           	         U R                  US/ 5      nU R                  USS5      nU R                  USS5      nU R                  USS5      nU R                  USS	5      nU R                  US
S5      nU R                  US5      n	U R                  USS5      n
U R                  USS5      nU R                  USS5      nU R                  USS5      nU R                  USS5      nU R                  USS5      nU R                  US5      nU R	                  U/ SQ5      nU R                  U/ SQ5      nU R                  US5      nUb  UnU R                  US5      nU R                  US5      n
U R                  US5      nU R                  US 5      nU R                  US!5      nU R                  US"5      nU R                  US#5      nU R                  US$5      nU R                  US%5      nU R                  US&5      n	U R                  US'5      nU R                  US(5      nU R                  XR5      nUS   nUc  U R                  US)S*5      nUc  [        R                  " U	S+5      nUc  Uc  U R                  US,U5      nOUnS nU R                  0 SU_SU_S-U R                  U5      _S.U
_S/U_S0U_S1U_S2U_S3U_S4S _S5U_S6U_S	U_S7S _S8S _S9U_S:U_UUU R                  US5      US;.EU5      $ )<Nr  	avg_priceindex_pricer  contract_symbol	timestampts
last_pricerK  price_change_percent_24h
change_24hfluctuationhigh_24h
high_pricelow_24h	low_pricebest_bidbid_pxbest_bid_sizebid_szbest_askask_pxbest_ask_sizeask_szopen_24h)base_volume_24hv_24h
volume_24h)quote_volume_24hqv_24hturnover_24hr      r   r      	   r      r   r   r   ro  r   s_trH  100r'  datetimehighlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechanger   average)
baseVolumequoteVolume
indexPriceru  )ry  safe_string_2safe_integer_2rv  safe_string_nsafe_string_lower_nre  r  safe_marketsafe_integer_productr6   
string_mulsafe_tickerr  )r[  r  r  r  r=  marketIdr  rK  r   r<  r2  r3  r4  r5  r6  r7  r9  r>  r?  listMarketIdr  s                        r]  parse_tickerbitmart.parse_ticker  s   h "5$$V[-H%%fh8IJ''TB	!!&,?''0JLY
!!&-8!!&*lC  K@  X>&&vI	  X>&&vI	
3''0Z[
..v7ef''2##H))&"5I##FA.D""61-C""61-C((3I""62.C((4I##FA.D##FA.D%%fa0F))&!4J00;K!!(3!11&%FI ++FE:J!"..v|[Q )!
 !
f!
!
 Y/!
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  *!!
" w#!
$ %&**6=A+!
, - 	r_  r  c                 2   U R                  5         U R                  U5      n0 nSnUS   (       a)  US   US'   U R                  U R                  XB5      5      nOTUS   (       a)  US   US'   U R	                  U R                  XB5      5      nO![        U R                  S-   US   -   S-   5      e/ n0 nUS   (       a  U R                  US	0 5      nO9U R                  US	0 5      nU R                  US
/ 5      nU R                  US0 5      nU R                  Xs5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

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

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
NrM   r<   r  rK   z  fetchTicker() does not support r"  1 markets, only spot and swap markets are acceptedra  r  r   )
r  r  r  r  publicGetSpotQuotationV3Tickerr.   r<   rd  ry  rK  )	r[  r  rf  r  r  rg  tickersr  ra  s	            r]  fetch_tickerbitmart.fetch_ticker"  s%    	V$&> &tGH::4;;w;WXHP F^ &tGH::4;;w;WXH0 tww)KKfU[n\  `S   S  T  T&>^^Hfb9F>>(FB7DnnT9b9G^^GQ3F  00r_  r  c                    U R                  5         U R                  U5      nSnSnUb#  U R                  US5      nU R                  U5      nU R	                  SXB5      u  p2SnUS:X  a  U R                  U5      nO6US:X  a  U R                  U5      nO[        U R                  S-   U-   S-   5      e/ nUS:X  a  U R                  US/ 5      nO&U R                  US0 5      nU R                  US	/ 5      n0 n	[        S[        U5      5       H=  n
0 nUS:X  a  U R                  S
Xz   05      nOU R                  Xz   5      nUS   nXU'   M?     U R                  U	SU5      $ )a6  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

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

:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r   rK   rM   z! fetchTickers() does not support rN  ra  r  r  r  )r  market_symbolsrv  r  handle_market_type_and_paramspublicGetSpotQuotationV3Tickersr  r.   r<   ry  rd  r  r  rK  filter_by_array_tickers)r[  r  rf  r"  r  r  rg  rP  ra  r  r  r  s               r]  fetch_tickersbitmart.fetch_tickers  s    	%%g.%%gq1F[[(F99.&Y6>;;FCH2 V^::6BHR tww)LLtS  WJ   J  K  K6>nnXvr:G>>(FB7DnnT9b9Gq#g,'AFv~**Hgj+AB**7:6H%F#6N ( ++FHgFFr_  rB  c                    U R                  5         U R                  U5      nSUS   0nSnUS   (       a(  Ub  X%S'   U R                  U R                  XS5      5      nOLUS   (       a!  U R	                  U R                  XS5      5      nO![        U R                  S-   US   -   S	-   5      eU R                  US
0 5      nU R                  USS5      nU R                  XtS   U5      $ )a>  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

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

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
r  r<   NrK   rB  rM   z# fetchOrderBook() does not support r"  rN  ra  r  r  )
r  r  publicGetSpotQuotationV3Booksr  publicGetContractPublicDepthr.   r<   rd  rB  parse_order_book)	r[  r  rB  rf  r  r  rg  ra  r  s	            r]  fetch_order_bookbitmart.fetch_order_book  s     	V$fTl
 &> #( 99$++g:VWHF^88W9UVHtww)NNQWX^Q__  cV   V  W  W\ ~~h3''dK@	$$T(+;YGGr_  tradec                 v   U R                  U/ SQ5      nU R                  US5      nUS LnS nS nS nS n	U(       a9  U R                  USS5      nU R                  US5      nU R                  USS5      n	OYU R                  U/ SQ5      nU R                  US	5      nU R                  US5      nU R	                  U R                  US
5      5      n	U R                  USS5      n
U R                  X5      nU R                  USS5      nS nUb;  U R                  US5      nU R                  U5      nUc  U	S:X  a  US   OUS   nUUS.nU R                  UU R                  U/ SQ5      U R                  USS5      UU R                  U5      US   UU	U R                  U/ SQ5      UUU R                  USS5      US.U5      $ )N)
createTimecreate_timer   r   countr   r  r"  r   )sizevolfillQtynotionalsider  r  	paid_feesfeeCoinNamebuyr  r  r  r  )tradeIdtrade_idlastTradeIDorderIdorder_id)rN  	fillPricero  	tradeRole	exec_type)ru  r<   orderr  r1  r  r"  ri  rN  r  r  takerOrMakerr  )
safe_integer_nrv  rA  rC  parse_order_siderE  r  
safe_trader  r  )r[  r`  r  r  isPublicisPublicTrader  r  r"  ri  rI  feeCostStringr  feeCurrencyIdfeeCurrencyCodes                  r]  parse_tradebitmart.parse_trade6  s   r ''/OP	##E1-!-''w:F##E84D%%eVQ7D''/IJF##E:6D##E62D(()9)9%)HID%%eXq9!!(3**5%E$ ,,UMBM"55mDO&59U]&.PW%+C $$U,RS''y*E"Y/X&''/HI 44UKU 
  	r_  sincec                 @   U R                  5         U R                  U5      nUS   (       d!  [        U R                  S-   US   -   S-   5      eSUS   0nUb  X6S'   U R	                  U R                  Xd5      5      nU R                  US/ 5      nU R                  XX#5      $ )	a  
get a list of the most recent trades for a particular symbol

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

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum number of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
rK   z  fetchTrades() does not support r"  & orders, only spot orders are acceptedr  r<   rB  ra  )r  r  r.   r<   publicGetSpotQuotationV3Tradesr  ry  parse_trades)	r[  r  r  rB  rf  r  r  rg  ra  s	            r]  fetch_tradesbitmart.fetch_trades  s     	V$f~tww)KKfU[n\  `H   H  I  IfTl
 $G66t{{77ST" ~~h3  u<<r_  c           
         [        U[        5      (       ah  U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ U R	                  USS5      U R                  US	S
5      U R                  USS5      U R                  USS5      U R                  USS5      U R                  USS5      /$ )Nr   r   ro  r   r   r   r  r  
open_priceor  hr  lclose_pricecvolumev)
isinstancer  safe_timestampr  safe_timestamp_2safe_number_2)r[  ohlcvr  s      r]  parse_ohlcvbitmart.parse_ohlcv  s    V eT""##E1-  *  *  *  *  *  %%e[$?""5,<""5,<""5+s;""5-=""5(C8 r_  r   	timeframec           	      b   U R                  5         SnU R                  USSS5      u  peU(       a  U R                  SXXBUS5      $ U R                  U5      nU R	                  U5      nU R                  U R                  U5      n	SUS   0n
U	b  XS'   OX*S'   US	   (       a:  U R                  S
XS5      u  pUb  XJS'   Ub  U R                  US-  5      S-
  U
S'   OSnUc  Un[        X5      nU R                  U R                  5       S-  5      nUc  XU-  -
  nXS'   XS'   O=U R                  US-  5      S-
  nU R                  XU-  5      nXS'   [        X5      U
S'   U R                  SXS5      u  pSnUS   (       al  U R                  US5      nUS:X  a3  U R                  US5      nU R                  U R                  X5      5      nOAU R!                  U R                  X5      5      nO U R#                  U R                  X5      5      nU R%                  US/ 5      nU R'                  UXrX45      $ )a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

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

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp of the latest candle in ms
:param boolean [params.paginate]: *spot only* default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns int[][]: A list of candles ordered, open, high, low, close, volume
Fr}   paginaterA  r  r<   NsteprK   beforegMbP?rB  rH  r   afterrP  
start_timerr  rM   rN  rL  ra  )r  handle_option_and_params"fetch_paginated_call_deterministicr  parse_timeframere  r   handle_until_optionparse_to_intr  millisecondssumrv  rw  %publicGetContractPublicMarkpriceKliner  publicGetContractPublicKlinepublicGetSpotQuotationV3Klinesry  parse_ohlcvs)r[  r  r  r  rB  rf  r  r  durationparsedTimeframer  maxLimitnowstartendrg  rN  r  s                     r]  fetch_ohlcvbitmart.fetch_ohlcv  sV     	88z[`a::<X]jpruvvV$''	2++DOOYGfTl
 &-FO'FO&>"66xRWXOG #(  #'#4#4edl#Dq#H H} (E##D$5$5$7$$>?C}h..(-%&)
#))54<9A=hhuh&67(-%&)#m
#"66z7TYZOG&>$$VW5E673EEdkkRYFbc<<T[[=YZ::4;;w;WXHD x4  5HHr_  c                 <   U R                  5         Sn0 nUb  U R                  U5      nUS   US'   SnSnU R                  SXT5      u  ptU R                  U/ SQ5      n	U R	                  US/5      nUS:X  a  Sn
U R                  SU5      u  pU
S:X  a  S	US
'   U R                  U R                  S0 5      nSnU R                  USU5      nUc  Un[        X<5      US'   Ub  X&S'   U	b  XS'   U R                  U R                  Xd5      5      nOnUS:X  aJ  Uc  [        U R                  S-   5      eUb  X&S'   U	b  XS'   U R                  U R                  Xd5      5      nO[        U R                  S-   U-   S-   5      eU R!                  US/ 5      nU R#                  XX#5      $ )a  

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

fetch all trades made by the user
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch trades for
:param boolean [params.marginMode]: *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders(only isolated margin orders are supported)
:param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nr<   r  r|   )untilendTimerr  r  rK   isolated
iso_margin	orderModerA  rB  	startTimer  rM   z+ fetchMyTrades() requires a symbol argumentr  rr  z" fetchMyTrades() does not support / orders, only spot and swap orders are acceptedra  )r  r  rU  rx  rw  handle_margin_mode_and_paramsrd  rU  re  r  privatePostSpotV4QueryTradesr  r'   r<   privateGetContractPrivateTradesr.   ry  r  )r[  r  r  rB  rf  r  r  r"  rg  r  r1  rU  r  defaultLimitra  s                  r]  fetch_my_tradesbitmart.fetch_my_tradesf  s     	[[(F &tGH99/6Z##F,LM6G9-6>J!%!C!COU[!\JZ''3$nnT\\?BGGH,,WgxHL}$"53GG ',$ %*	"88W9UVHV^~'2_(_`` (-% &+
#;;DKK<XYHtww)MMPTT  XI   I  J  Jh ~~h3  u<<r_  r<   c                     U R                  5         SU0nU R                  U R                  Xe5      5      nU R                  US/ 5      nU R	                  USX45      $ )aj  

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

fetch all the trades made from a single order
:param str id: order id
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
rq  ra  N)r  !privatePostSpotV4QueryOrderTradesr  ry  r  )	r[  r<   r  r  rB  rf  r  rg  ra  s	            r]  fetch_order_tradesbitmart.fetch_order_trades  s^     	r
 99$++g:VW~~h3  tU::r_  c                    U R                  US0 5      nS nUS:X  a  U R                  US/ 5      nO-US:X  a  U R                  US/ 5      nOU R                  US/ 5      nSU0nUS:X  a  [        S[        U5      5       H  nXF   nU R	                  US5      nU R                  US S	5      n	U R                  US
0 5      n
U R                  US0 5      nU R                  U R	                  U
S5      5      nU R                  U R	                  US5      5      n0 nU R                  U
5      X'   U R                  U5      X'   U R                  U5      XY'   M     U$ [        S[        U5      5       H  nXF   nU R                  USS5      nU R	                  USU5      nU R                  U5      nU R                  5       nU R                  USS5      US'   U R                  U/ SQ5      US'   UUU'   M     U R                  U5      $ )Nra  rM   rL   r  walletru  r   r  _r  r  r  r<   	coin_code	availableavailable_balancefree)unAvailablefrozenfrozen_balanceused)rd  ry  r  r  rv  safe_symbolr  parse_balance_helpersafe_balancerA  accountrC  )r[  rg  
marketTypera  r  r  r  r  rI  r  r  r  baseCode	quoteCode	subResultbalancer  r  r  s                      r]  custom_parse_balancebitmart.custom_parse_balance  s    ~~h3^^Hfb9F8#^^D)R8F^^D(B7F(#!1c&k*	++E8<))(D#>~~eVR8ugr:2243C3CD*3UV 33D4D4DUJ4WX	"$	&*&?&?&E	#'+'@'@'G	$!%!2!29!= + M1c&k* )!//zJ
!--g{JO
..z:,,."&"4"4WkK^"_"&"4"4W>i"j&t + $$V,,r_  c                    U R                  5       nU R                  US5      US'   U R                  US5      US'   U R                  US5      US'   U R                  US5      nU R                  US5      n[        R                  " X45      US	'   U$ )
Nr  r  r  r  total_assettotalborrow_unpaidinterest_unpaiddebt)r  rv  r6   
string_add)r[  r  r  r  interests        r]  r  bitmart.parse_balance_helper	  s    ,,.**5(;**5+>++E=A7##E+<=!,,T<r_  c                    U R                  5         SnU R                  SSU5      u  p!U R                  US5      nU R                  USS5      nU R	                  USS/5      nUc  U(       a  SnSnUS:X  a  U R                  U5      nOfUS:X  a  U R                  U5      nONUS:X  a  U R                  U5      nO6US:X  a  U R                  U5      nO[        U R                  S	-   U-   S
-   5      eU R                  XR5      $ )a0  
query for balance and get the amount of funds available for trading or funds locked in orders

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr`   r1  rL   FrK   rM   r  z! fetchBalance() does not support zE markets, only spot, swap and account and margin markets are accepted)r  rU  rv  r  rw  privateGetSpotV1Wallet%privateGetContractPrivateAssetsDetailprivateGetAccountV1Wallet%privateGetSpotV1MarginIsolatedAccountr.   r<   r  )r[  rf  r  r1  isMarginrg  s         r]  fetch_balancebitmart.fetch_balance	  s    	
!??PTV\]
%%fl;
>>&(E:6Hl#;<!X!J226:H6!AA&IH9$55f=H8#AA&IHtww)LLzY  ]d   d  e  e~ ((>>r_  r  c                     U R                  US5      nU R                  U5      nUUU R                  US5      U R                  US5      S S S.$ )Nr  maker_fee_ratetaker_fee_rate)ru  r  r   r   r   r   )rv  r  r  )r[  r  r  rI  r  s        r]  parse_trading_feebitmart.parse_trading_fee	  s^     ##C2!!(+%%c+;<%%c+;<
 	
r_  c                 0   U R                  5         U R                  U5      nUS   (       d!  [        U R                  S-   US   -   S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nU R                  U5      $ )a5  
fetch the trading fees for a market

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
rK   z$ fetchTradingFee() does not support r"  r  r  r<   ra  )r  r  r.   r<   privateGetSpotV1TradeFeer  rd  r  r[  r  rf  r  r  rg  ra  s          r]  fetch_trading_feebitmart.fetch_trading_fee	  s     	V$f~tww)OORXY_R``  dL   L  M  MfTl
 00W1MN ~~h3%%d++r_  rv  c                     S n[        U[        5      (       a  Un0 nU R                  USSU5      nU R                  USS5      nU R	                  US5      nU R                  XR5      nU R                  Xb5      nU R	                  USS5      nU R	                  US5      nS n	S n
US:X  a  S	nS
n
Sn	US:X  a  S	nSn	U R	                  US5      nUS:X  a  S nU R                  US5      nU R                  0 SU_SU R                  USS5      _SU_SU_SU R                  U5      _SU R                  US5      _SU_SU_SU	_SU
_SU R                  U R	                  US5      5      _SU R                  U5      _SU_SU R                  U R	                  US5      5      _SU R                  US S!5      _S"U R                  U/ S#Q5      _S$U R                  U/ S%Q5      _S U R                  XpR                  US&S'5      5      S S S(.EU5      $ ))Nrr  rq  rc  rb  r  r"  rK   limit_makerrB  Tr/  iocr-  rN  zmarket priceactivation_pricer<   clientOrderIdclient_order_idru  r  r1  lastTradeTimestampupdate_timer8  postOnlyri  r2  r  re  r  filled_notionalfilledNotionalr=  )	price_avgpriceAvgdeal_avg_pricefilled)filled_size
filledSize	deal_sizern  state)	remainingrn  r  trades)r  strrA  rB  rv  r  rE  r  
safe_orderr  re  ry  	omit_zerorC  parse_order_status_by_type)r[  rv  r  r<   r  rI  r  	orderTyper"  r8  r  priceStringtrailingActivationPrices                r]  parse_orderbitmart.parse_order	  s   X eS!!BEz9bA''}lK	##E84!!(3!!&1$$VVV<	v.= DHK5=DK&&ug6.(K"&"2"25:L"M  
" 
T//7H/Z 
 E 
 	 

 Y/ 
 !$"3"3E="I 
 f 
 D 
 ; 
  
 D))$*:*:5&*IJ 
 T^^K0 
 3 
 dnnT%5%5eV%DE 
 D&&u.?AQR 
  t))%1\]! 
" d((0Z[# 
$ 55iASASTY[celAmn+ 
, - 	r_  c                 4    SSSSS.nU R                  X!U5      $ )Nrl  sell)1234rv  )r[  ri  sidess      r]  ry  bitmart.parse_order_sideD
  s*    	
 T22r_  c                 v    SSSSSSSSSSSSS.SSSS.S.nU R                  X10 5      nU R                  XBU5      $ )Nrejectedr9  closedcanceled)r  r  r  r  5678newpartially_filledr  partially_canceled)r  r  r  r   )rd  rv  )r[  r"  rn  statusesByTypestatusess        r]  r  "bitmart.parse_order_status_by_typeM
  si      $*"&0  
* >>.;&99r_  r  c                     U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS'   U R	                  USSUSU5      $ )a  
create a market buy order by providing the symbol and cost

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

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
rK   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr+  r  rl  N)r  r  r.   r<   create_order)r[  r  r  rf  r  s        r]  !create_market_buy_order_with_cost)bitmart.create_market_buy_order_with_costf
  s`     	V$f~tww)ddee6;23  5$fMMr_  r"  ri  r  rN  c                 $   U R                  5         U R                  U5      nU R                  SU5      nU R                  US5      n	U R	                  U/ SQ5      n
U R                  US5      nU R                  US5      nUSLnUSLnU
SLnSnUS   (       a=  U R                  XX4XV5      nU	S:X  a  U R                  U5      nOU R                  U5      nOU R                  XX4XV5      nU R                  US	5      nUb  U R                  U5      nOJU(       a  U R                  U5      nO1U(       d  U(       a  U R                  U5      nOU R                  U5      nU R                  US
0 5      nU R                  UU5      nUUS'   UUS'   UUS'   UUS'   U$ )a3	  
create a trade order

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

:param str symbol: unified symbol of the market to create an order in
:param str type: 'market', 'limit' or 'trailing' for swap markets only
:param str side: 'buy' or 'sell'
:param float amount: how much of currency you want to trade in units of base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated'
:param str [params.leverage]: *swap only* leverage level
:param str [params.clientOrderId]: client order id of the order
:param boolean [params.reduceOnly]: *swap only* reduce only
:param boolean [params.postOnly]: make sure the order is posted to the order book and not matched immediately
:param str [params.triggerPrice]: *swap only* the price to trigger a stop order
:param int [params.price_type]: *swap only* 1: last price, 2: fair price, default is 1
:param int [params.price_way]: *swap only* 1: price way long, 2: price way short
:param int [params.activation_price_type]: *swap trailing order only* 1: last price, 2: fair price, default is 1
:param str [params.trailingPercent]: *swap only* the percent to trail away from the current market price, min 0.1 max 5
:param str [params.trailingTriggerPrice]: *swap only* the price to trigger a trailing order, default uses the price argument
:param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
:param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
:param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
:param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
rX   r   r2  	stopPricetrigger_pricer5  r6  NrK   r  r  ra  r"  ri  r  rN  )r  r  r  rv  rC  create_spot_order_request"privatePostSpotV1MarginSubmitOrderprivatePostSpotV2SubmitOrdercreate_swap_order_request*privatePostContractPrivateSubmitTrailOrder)privatePostContractPrivateSubmitPlanOrder)privatePostContractPrivateSubmitTpSlOrder%privatePostContractPrivateSubmitOrderrd  r  )r[  r  r"  ri  r  rN  rf  r  r  r1  r2  r5  r6  
isStopLossisTakeProfitisTriggerOrderrg  spotRequestswapRequestactivationPricera  rv  s                         r]  r,  bitmart.create_orderx
  s   D 	V$33M6J%%fa0
))&2`a((A**63DE"$.
&d2%T1&>88tUZcKZ'BB;O<<[I88tUZcK"..{<NOO*JJ;WII+V|II+VEEkR  ~~h3  v.ff hgr_  ordersc           	         U R                  5         / nSnSn[        S[        U5      5       GH  nX   nU R                  US5      nU R	                  U5      nUS   (       d  [        U R                  S-   5      eUc  UnOXH:w  a  [        U R                  S-   5      eU R                  US5      n	U R                  US5      n
U R                  US	5      nU R                  US
5      nU R                  US0 5      nU R                  XXX5      nU R                  US/5      nUR                  U5        GM     US   US.nU R                  U5      nU R                  US0 5      nU R                  US0 5      nU R                  US/ 5      n/ n[        S[        U5      5       H-  nUU   nU R                  SU0U5      nUR                  U5        M/     U$ )a8  
create a list of trade orders

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

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]:  extra parameters specific to the exchange API endpoint
:param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r  rK   z) createOrders() supports spot orders onlyz; createOrders() requires all orders to have the same symbolr"  ri  r  rN  rf  r<   )r  orderParamsra  orderIds)r  r  r  rv  r  r.   r<   r(   r  rd  r3  rw  r  privatePostSpotV4BatchOrdersry  r  )r[  rB  rf  ordersRequestsr  r  r  rawOrderrI  r"  ri  r  rN  rD  orderRequestr  rg  ra  
innderDatarE  parsedOrdersrq  rv  s                          r]  create_ordersbitmart.create_orders
  s    	q#f+&AyH''(;H[[*F&>"477-X#XYY~!%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E..8R@K99($X]kL99\H:>L!!,/% '( Tl)
 44W=" ~~h3^^D&"5
>>*j"=q#h-(AqkGOOT7OV<E& ) r_  c                 0   U R                  U5      nU R                  US5      nU R                  US5      n	USLn
U	SLnU
(       a  SnO	U(       a  SnUS   [        U R                  X5      5      S.nU R                  US5      nU R	                  US	5      nUS
:H  nSnU R                  US5      nUS:H  nU R                  UUU5      u  nnUS:H  =(       d    US:H  nUS:H  =(       d    U=(       d    UnUS:X  a  SUS	'   OUS:X  a  SUS	'   OUS:X  a  SUS	'   U(       a  SUS	'   U R                  U/ SQ5      nUSLnU R                  USSU R                  U5      5      nU R                  USS5      nUSLnU(       a  U R                  X5      US'   O?US:X  d  U(       a2  SnUUS'   U R                  UU5      US'   U R	                  USS5      US'   U(       az  U(       d  Ub  U R                  X5      US'   U R                  UU5      US'   U R	                  USS5      US'   US:X  a  U(       a  SUS '   OSUS '   OUS!:X  a  U(       a  SUS '   OSUS '   SnU R                  S"US#5      u  nnU
(       d  U(       a]  S$nU R	                  USS5      US'   U R                  X5      US'   U
(       a  U R                  X5      US'   OU R                  X5      US'   OUUS%'   US:X  a  U(       a  SUS&'   OSUS&'   OUS!:X  a  U(       a  SUS&'   OSUS&'   U R                  US'5      nUb  U R                  US'5      nUUS('   U R	                  US)5      nU R                  U/ S*Q5      nUb  U R                  U5      US)'   OU(       a  S+US)'   US:w  a  X,S,'   U R                  X5      $ )-a  
@ignore
       create a trade order
       https://developer-pro.bitmart.com/en/futuresv2/#submit-order-signed
       https://developer-pro.bitmart.com/en/futuresv2/#submit-plan-order-signed
       https://developer-pro.bitmart.com/en/futuresv2/#submit-tp-sl-order-signed
       https://developer-pro.bitmart.com/en/futuresv2/#submit-trail-order-signed
       :param str symbol: unified symbol of the market to create an order in
       :param str type: 'market', 'limit', 'trailing', 'stop_loss', or 'take_profit'
       :param str side: 'buy' or 'sell'
       :param float amount: how much of currency you want to trade in units of base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param int [params.leverage]: leverage level
       :param boolean [params.reduceOnly]: *swap only* reduce only
       :param str [params.marginMode]: 'cross' or 'isolated', default is 'cross'
       :param str [params.clientOrderId]: client order id of the order
       :param str [params.triggerPrice]: *swap only* the price to trigger a stop order
       :param int [params.price_type]: *swap only* 1: last price, 2: fair price, default is 1
       :param int [params.price_way]: *swap only* 1: price way long, 2: price way short
       :param int [params.activation_price_type]: *swap trailing order only* 1: last price, 2: fair price, default is 1
       :param str [params.trailingPercent]: *swap only* the percent to trail away from the current market price, min 0.1 max 5
       :param str [params.trailingTriggerPrice]: *swap only* the price to trigger a trailing order, default uses the price argument
       :param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
       :param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
       :param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
       :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
       r5  r6  N	stop_losstake_profitr<   )r  re  r8  moder  
reduceOnlyr   r-  r   rB  GTCr   r.  ro  r0  trailingTriggerPricer  trailingPercentcallback_raterN  r:  activation_price_typeexecutive_pricer2  
price_typerl  	price_wayr  rX   crossT	open_typeri  r  r  r=  )
r8  r  rR  r=  rT  rU  r2  r1  r5  r6  r  r"  )r  rv  intamount_to_precisionre  r  handle_post_onlyrC  rA  number_to_stringprice_to_precisionr  rw  r  )r[  r  r"  ri  r  rN  rf  r  r5  r6  r;  r<  r  r8  rQ  isMarketOrderr  rR  isExchangeSpecificPor  isLimitOrderr2  r=  rT  rU  isTrailingPercentOrderr1  r  r=  s                                r]  r6  !bitmart.create_swap_order_request  s   : V$((A**63DE"$.
&d2D DTl00@A
 &&v}=  0(^^FL9
 $	00@TV\]&u$4$!);H;%GFOE!GFOE!GFOGFO))&2`a%T1#11&:PRdfjf{f{  }B  gC   D,,V5FX!0!<#66vEGGZ#9D'6GO$*.*A*A&J^*_G&'/3/@/@I`bc/dG+,u0-1-D-DV-S)*'+'>'>v|'TGO$$($5$5flA$NGL!u}+,GK(+,GK(+,GK(+,GK(
!??vW^_
FJ$($5$5flA$NGL!)-)@)@)OG%&+/+B+B6+Y(+/+B+B6+[(#-GK 5="#"#V^"#"#((A$YYv7F)6G%&$$VZ86  $E  F"&"7"7"AGJ"%GJ:"FO{{7++r_  c                    U R                  U5      nUS   UUS.nU R                  US5      n	U	S:X  a  [        U R                  S-   5      eU R	                  US5      n
US:H  nSnUS	:H  =(       d    U
S
:H  nU R                  XU5      u  pU R                  USS/5      nU	S:H  =(       d    US:H  nUS:H  =(       d    U=(       d    UnU(       a*  U R                  X5      US'   U R                  X5      US'   GOU(       a  US:X  a  U R                  USS5      nU R                  US5      nSnU R                  USSS5      u  nnU(       aX  Uc  Uc  [        U R                  S-   5      eU R                  U5      nU R                  U5      n[        R                  " UU5      nOUc  U R                  U5      OUnU R                  U[        US   S   U R                   5      US'   OUS:X  a  U R                  X5      US'   U(       a  S	US'   U(       a  SUS'   U R                  US5      nUb  U R                  US5      nUUS'   U R#                  X5      $ )a5  
@ignore
       create a spot order request
       https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
       https://developer-pro.bitmart.com/en/spot/#new-margin-order-v1-signed
       :param str symbol: unified symbol of the market to create an order in
       :param str type: 'market' or 'limit'
       :param str side: 'buy' or 'sell'
       :param float amount: how much of currency you want to trade in units of base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param str [params.marginMode]: 'cross' or 'isolated'
       :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
       r<   )r  ri  r"  r8  r.  zE createOrder() only accepts timeInForce parameter values of IOC or POrQ  r  Nr  r   r  r-  r  rB  re  rN  rl  r  rh  TrX   r+  a?   createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argument or in the "notional" extra parameter(the exchange-specific behaviour)r  r  r"  r  r  )r  rv  r,   r<   re  r_  rw  r^  ra  rA  r  r`  r6   rG  decimal_to_precisionr4   r   r  )r[  r  r"  ri  r  rN  rf  r  r  r8  rQ  rb  r  rc  r  rd  rh  r+  amountStringr  r  s                        r]  r3  !bitmart.create_spot_order_request  s    V$Tl

 &&v}=%tww)ppqq  0( $ 5E41900V\]6M:#>?u$8$%-;H;"66vFGFO#66vEGGu}--ffjI662481<@<Y<YZ`bo  rU  W[  =\9164H,<*477  6w  ,w  x  x'+'<'<V'D&*&;&;E&B#*#5#5lK#PAIAQt44V<X`H&*&?&?(TZ[fTghoTprv  sE  sE  'F
#"&":":6"J+GFO#GFO((A$YYv7F)6G%&{{7++r_  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nU R	                  USS5      nUb  XeS'   O[        U5      US'   U R                  US/5      nSnUS   (       a!  U R                  U R                  XS5      5      nOU R                  US	S
5      nU R                  US5      n	U R                  US	S
/5      nU(       a!  U R                  U R                  XS5      5      nOHU	(       a!  U R                  U R                  XS5      5      nO U R                  U R                  XS5      5      nUS   (       a  U R                  SU05      $ U R                  US5      n
U
SL a  U R                  SU0U5      $ U R                  U
S5      nUb7  U R!                  US5      nUc!  [#        U R                  S-   U-   S-   U-   5      eO=U R                  U
S5      nU(       d$  [#        U R                  S-   U-   S-   U-   S-   5      eU R                  XS   0 S.U5      nU$ )ao  
cancels an open order

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

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.clientOrderId]: *spot only* the client order id of the order to cancel
:param boolean [params.trigger]: *swap only* whether the order is a trigger order
:param boolean [params.trailing]: *swap only* whether the order is a stop order
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz) cancelOrder() requires a symbol argumentr  r<   r  r  rr  rK   stoprF  r:  rM   ru  ra  Tsucceedr   z  cancelOrder() failed to cancel z
 order id r  z cancelOrder() z is filled or canceled)r<   r  ru  )r'   r<   r  r  rA  r  rw  privatePostSpotV3CancelOrderr  safe_bool_2r  )privatePostContractPrivateCancelPlanOrder*privatePostContractPrivateCancelTrailOrder%privatePostContractPrivateCancelOrderr  r  rv  r,   )r[  r<   r  rf  r  r  r  rg  rF  r:  ra  	succeededr  rv  s                 r]  cancel_orderbitmart.cancel_order  sC   $ >#DGG.Y$YZZV$fTl
 **6?DUV$)6%&"%b'GJ6O#45&>88W9UVH&&vvyAG~~fj9HYYv	':;FII$++V]JfgJJ4;;W^KghEEdkkRYFbc0 &>??FH#566x04<??D":v66OOD)4	 !!)Q/Bz"477-O#ORX#X[g#gjl#lmm  __T84F"477->#>#G,#VY[#[^v#vwwrH5Er RTZ[r_  idsc                 
   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   (       d!  [	        U R                  S-   US   -   S-   5      eU R                  US5      nU R                  US/5      nSUS   0nUb  XVS'   OXS	'   U R                  U R                  Xc5      5      nU R                  US
0 5      n/ n	U R                  US/ 5      n
[        S[        U
5      5       H+  nX   nU	R                  U R                  USS.U5      5        M-     U R                  US/ 5      n[        S[        U5      5       H+  nX   nU	R                  U R                  USS.U5      5        M-     U	$ )a  
cancel multiple orders

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

:param str[] ids: order ids
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str[] [params.clientOrderIds]: client order ids
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
z* cancelOrders() requires a symbol argumentrK   z! cancelOrders() does not support r"  r  clientOrderIdsr  r<   rE  ra  
successIdsr   r   )r<   rn  failIdsfailed)r'   r<   r  r  r.   ry  rw  privatePostSpotV4CancelOrdersr  rd  r  r  r  r  )r[  rv  r  rf  r  rx  r  rg  ra  	allOrdersry  r  r<   rz  s                 r]  cancel_ordersbitmart.cancel_orders  s    >#DGG.Z$Z[[V$f~tww)LLvV\~]  aI   I  J  J0@A6$4#56fTl
 %(6$%"%J55dkk'6RS" ~~h3	^^D,;
q#j/*ABT__B*-MvVW + ..y"5q#g,'ABT__B(-KVTU ( r_  c                    U R                  5         0 nSnUb  U R                  U5      nUS   US'   SnSnU R                  SXB5      u  pbUS:X  a!  U R                  U R	                  X25      5      nOAUS:X  a;  Uc  [        U R                  S-   5      eU R                  U R	                  X25      5      nU R                  SU05      /$ )	a  
cancel all open orders in a market

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

:param str symbol: unified market symbol of the market to cancel orders in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.side]: *spot only* 'buy' or 'sell'
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr<   r  rR   rK   rM   z- cancelAllOrders() requires a symbol argumentru  )	r  r  rU  privatePostSpotV4CancelAllr  r'   r<   &privatePostContractPrivateCancelOrdersr  )r[  r  rf  r  r  rg  r"  s          r]  cancel_all_ordersbitmart.cancel_all_ordersV  s     	[[(F &tGH99:KV\6>66t{{77STHV^~'2a(abbBB4;;wC_`H&  2344r_  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   (       d!  [	        U R                  S-   US   -   S-   5      eUS   SSS	.nUS
:X  a  SUS'   OUS:X  a  SUS'   OUS:X  a  SUS'   OXS'   U R                  U R                  Xu5      5      nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  XX45      $ )Nz1 fetchOrdersByStatus() requires a symbol argumentrK   z( fetchOrdersByStatus() does not support r"  r  r<   r   rO  )r  offsetNr9  r-  rn  r  r   r   r,  ra  rB  )
r'   r<   r  r  r.   privateGetSpotV3Ordersr  rd  ry  parse_orders)r[  rn  r  r  rB  rf  r  r  rg  ra  rB  s              r]  fetch_orders_by_statusbitmart.fetch_orders_by_status  s   >#DGG.a$abbV$f~tww)SSV\]cVdd  hP   P  Q  QTl

 V !GHx !GHz! !GH &H..t{{7/KL: ~~h3h3  >>r_  c                    U R                  5         Sn0 nUb  U R                  U5      nUS   US'   SnSnU R                  SXT5      u  ptUS:X  a  Ub  [        US5      US'   Sn	U R	                  SU5      u  pU	S:X  a  S	US
'   Ub  X&S'   U R                  USS5      n
U
b  U R                  US/5      nXS'   U R                  U R                  Xd5      5      nOUS:X  a  Ub  [        US5      US'   U R                  USS5      nU R                  USS/5      nU(       a!  U R                  U R                  Xd5      5      nOU R                  USS5      nU R                  US5      nU R                  USS/5      nU(       a  SnUb  XS'   U R                  U R                  Xd5      5      nO[        U R                  S-   U-   S-   5      eU R!                  US/ 5      nU R#                  XX#5      $ )a  

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

fetch all unfilled currently open orders
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch open orders for
:param int [limit]: the maximum number of open order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.marginMode]: *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders(only isolated margin orders are supported)
:param int [params.until]: *spot* the latest time in ms to fetch orders for
:param str [params.type]: *swap* order type, 'limit' or 'market'
:param str [params.order_state]: *swap* the order state, 'all' or 'partially_filled', default is 'all'
:param str [params.orderType]: *swap only* 'limit', 'market', or 'trailing'
:param boolean [params.trailing]: *swap only* set to True if you want to fetch trailing orders
:param boolean [params.trigger]: *swap only* set to True if you want to fetch trigger orders
:param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr<   r  r   rK   rA  rB  r  r  r  r  r  r  rM   rO  rl  rF  r:  Fr  r"  z$ fetchOpenOrders() does not support r  ra  )r  r  rU  r  r  rB  rw   privatePostSpotV4QueryOpenOrdersr  ro  )privateGetContractPrivateCurrentPlanOrderr  rv  &privateGetContractPrivateGetOpenOrdersr.   r<   ry  r  )r[  r  r  rB  rf  r  r  r"  rg  r1  r  	isTriggerr:  r  ra  s                  r]  fetch_open_ordersbitmart.fetch_open_orders  s"   , 	[[(F &tGH99:KV\6> #&uc? J!%!C!CDUW]!^JZ''3$ ',$''CE 6I;7%*	"<<T[[=YZHV^ #&uc? ((CIYYv	':;FII$++V]Jfg>>&*eD ,,V[A	6K+DE *I(&/FOFFt{{SZGcdtww)OORVV  ZK   K  L  Ln ~~h3  u<<r_  c                 ~   U R                  5         Sn0 nUb  U R                  U5      nUS   US'   SnU R                  SXT5      u  ptUS:w  a  Uc  [        U R                  S-   5      eUb  US:X  a  SOSnX&U'   US:X  a  S	OS
n	U R                  USU	5      n
U
b  U R                  US/5      nXU	'   SnUS:X  aB  SnU R                  SU5      u  pUS:X  a  SUS'   U R                  U R                  Xd5      5      nO U R                  U R                  Xd5      5      nU R                  US/ 5      nU R                  XX#5      $ )ak  

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

fetches information on multiple closed orders made by the user
:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest entry
:param str [params.marginMode]: *spot only* 'cross' or 'isolated', for margin trading
:param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr<   r  re   rK   z/ fetchClosedOrders() requires a symbol argumentr  r  r  rr  r  r  r  r  ra  )r  r  rU  r'   r<   rB  rw  r  #privatePostSpotV4QueryHistoryOrdersr  %privateGetContractPrivateOrderHistoryry  r  )r[  r  r  rB  rf  r  r  r"  startTimeKey
endTimeKeyr  rg  r1  ra  s                 r]  fetch_closed_ordersbitmart.fetch_closed_orders2  sd     	[[(F &tGH99:Mv^6>~'2c(cdd+/6>;L$)L!#'6>Y

##FGZ@YYvy1F"'J6>J!%!C!CDWY_!`JZ''3$??G@\]HAA$++gB^_H~~h3  u<<r_  c                 (    U R                  SXX45      $ )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[  r  r  rB  rf  s        r]  fetch_canceled_ordersbitmart.fetch_canceled_ordersa  s     **:veTTr_  c                    U R                  5         0 nSnSnSnUb  U R                  U5      nU R                  SXc5      u  pSUS:X  ab  U R                  US5      nU(       d  XS'   Ub!  U R	                  U R                  XC5      5      nOU R                  U R                  XC5      5      nOUS:X  a  Uc  [        U R                  S-   5      eU R                  USS	5      n	U R                  US
5      n
U R                  US
S/5      nU	(       a  Sn
U
b  XS'   US   US'   XS'   U R                  U R                  XC5      5      nU R                  US0 5      nU R                  X5      $ )a  
fetches information on an order made by the user

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

:param str id: the id of the order
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.clientOrderId]: *spot* fetch the order by client order id instead of order id
:param str [params.orderType]: *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
:param boolean [params.trailing]: *swap only* set to True if you want to fetch a trailing order
:param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   rK   r  rq  rM   z( fetchOrder() requires a symbol argumentr:  Fr  r"  r<   r  rr  ra  )r  r  rU  rv  !privatePostSpotV4QueryClientOrderr  privatePostSpotV4QueryOrderr'   r<   r  rw  privateGetContractPrivateOrderrd  r  )r[  r<   r  rf  r  r"  r  rg  r  r:  r  ra  s               r]  fetch_orderbitmart.fetch_orderl  sl   " 	[[(F99,W6> ,,V_EM %'	"(AA$++gB^_;;DKK<XYV^~'2\(\]]~~fj%@H((=IYYvZ'@AF&	$"+ &tGH"$J::4;;w;WXHf ~~h3--r_  c                    U R                  5         U R                  U5      nSnU R                  U5      u  pBSU R                  X5      0nU R	                  U R                  XR5      5      nU R                  US0 5      nU R                  Xs5      $ )aT  
fetch the deposit address for a currency associated with self account

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

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
Nr  ra  )r  r  r   r  !privateGetAccountV1DepositAddressr  rd  parse_deposit_address)r[  r  rf  r  r  r  rg  ra  s           r]  fetch_deposit_addressbitmart.fetch_deposit_address  s     	==&==fEBB4Q
 99$++g:VW ~~h3))$99r_  c           	         U R                  US5      nU R                  USS5      nUR                  S5      S:  a:  UR                  S5      nU R                  US5      nU R                  US5      nUb  UnU R                  US5      nU R	                  X25      nU R                  U5        UU R                  US	5      U R                  U5      UU R                  US
S5      S.$ )Nr  chainr  r  r   r  r   addressr  address_memomemo)ru  r  r  r  tag)rv  rA  r  r  safe_currencycheck_addressr  )r[  depositAddressr  r  r  r  
secondPartr  s           r]  r  bitmart.parse_deposit_address  s    * %%njA
$$^WiH??5!A%$$S)E))%3J))%3J%$"">9=%%j;7#"((6:..w7%%nnfM
 	
r_  r  r  c                    U R                  XE5      u  pEU R                  U5        U R                  5         U R                  U5      nSnU R	                  U5      u  puU R                  X5      USUS.nUb  XHS'   U R                  U R                  X5      5      n	U R                  U	S0 5      n
U R                  X5      nU R                  UUUUS.5      $ )a  
make a withdrawal

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

:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: the network name for self withdrawal
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
NzTo Digital Address)r  r  destinationr  r  ra  )r  r  r  )
handle_withdraw_tag_and_paramsr  r  r  r   r  !privatePostAccountV1WithdrawApplyr  rd  parse_transaction)r[  r  r  r  r  rf  r  r  r  rg  ra  transactions               r]  r   bitmart.withdraw  s     99#F7#==&==fEBB4Q/	
 ?&)N#99$++g:VW ~~h3,,T<{{;)
  	r_  c                    U R                  5         Uc  SnUUS.nS nUb  U R                  U5      nUS   US'   Ub  X6S'   U R                  US5      nUb  U R                  US5      nXS'   U R	                  U R                  Xe5      5      n	U R                  U	S0 5      n
U R                  U
S	/ 5      nU R                  XX45      $ )
NrH  )operation_typer  r<   r  r  r  r  ra  records)	r  r  re  rw  )privateGetAccountV2DepositWithdrawHistoryr  rd  ry  parse_transactions)r[  r"  r  r  rB  rf  r  r  r  rg  ra  r  s               r]  fetch_transactions_by_type"bitmart.fetch_transactions_by_typeH  s    =E"
 }}T*H"*4.GJ#(K !!&'2YYvw/F!&IAA$++gB^_2 ~~h3..y"5&&w%GGr_  c                     U R                  5         SU0nU R                  U R                  XC5      5      nU R                  US0 5      nU R                  US0 5      nU R	                  U5      $ )al  
fetch information on a deposit

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

:param str id: deposit id
:param str code: not used by bitmart fetchDeposit()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
r<   ra  recordr  (privateGetAccountV1DepositWithdrawDetailr  rd  r  r[  r<   r  rf  r  rg  ra  r  s           r]  fetch_depositbitmart.fetch_depositw  n     	"
 @@WA]^. ~~h3h3%%f--r_  c                 (    U R                  SXX45      $ )a  
fetch all deposits made to an account

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

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
r  r  r[  r  r  rB  rf  s        r]  fetch_depositsbitmart.fetch_deposits  s     ..y$uUUr_  c                     U R                  5         SU0nU R                  U R                  XC5      5      nU R                  US0 5      nU R                  US0 5      nU R	                  U5      $ )a  
fetch data on a currency withdrawal via the withdrawal id

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

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

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

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch withdrawals for
:param int [limit]: the maximum number of withdrawals structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
r   r  r  s        r]  fetch_withdrawalsbitmart.fetch_withdrawals  s     ..z4VVr_  rn  c                 8    SSSSSSS.nU R                  X!U5      $ )Npendingrp  r   r{  )r   r  r  r  r  r!  r  r[  rn  r)  s      r]  parse_transaction_status bitmart.parse_transaction_status  s0    
 &99r_  r  c                 l   S nU R                  US5      nU R                  US5      nS nUb  US:w  a  SnUnOUb
  US:w  a  SnUnU R                  US5      nU R                  US5      nU R                  US5      n	S n
U	bJ  U	R                  S	5      S
:  a5  U	R	                  S5      nU R                  US
5      n	U R                  US5      n
U R                  X5      nU R                  U R                  US5      5      nU R                  US5      nS nUb  UUS.nU R                  US5      nU R                  US5      nU R                  US5      n0 SU_SU_SU_SU_SU R                  U
5      _SU_SS _SS _SU_SS _SS _SU_SU_SS _SU_SS _S S _US
:w  a  UOS US
:w  a  U R                  U5      OS US!.E$ )"Nwithdraw_id
deposit_id r   r  arrival_amount
apply_timer  r  r   r  r   rn  r  rm  tx_idr  r  ru  r<   r  r  addressFrom	addressTor  tagFromtagTor"  rs  txidinternalcomment)r  r1  r  )	rv  r  re  r  r  r  r  r  r  )r[  r  r  r<   
withdrawId	depositIdr"  r  r  r  r  r  r  rn  feeCostr  r  r  r  s                      r]  r  bitmart.parse_transaction  s{   0 %%k=A
$$[,?	"r)9DB#)r/DB!!+/?@%%k<@	%%k:>
	!u%)"((-!--eQ7
 ,,UA6	&&z<..t/?/?X/VW"";6 C W5"";	:{N;
K
"
 
 f	

 t..y9
 w
 4
 
 3
 t
 T
 f
 D
 t
 D
  !
" t#
$ (1A~D4=NY/)
 	
r_  c                 N   U R                  5         U R                  U5      nU R                  U5      nUS   US   U R                  X#5      S.nU R	                  U R                  Xt5      5      nU R                  US0 5      n	U R                  X5      n
U R                  U
UUS.5      $ )a  
repay borrowed margin and interest

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

:param str symbol: unified market symbol
:param str code: unified currency code of the currency to repay
:param str amount: the amount to repay
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
r<   r  r  r  ra  r  r  )r  r  r  currency_to_precision$privatePostSpotV1MarginIsolatedRepayr  rd  parse_margin_loanr[  r  r  r  rf  r  r  r  rg  ra  r  s              r]  repay_isolated_marginbitmart.repay_isolated_margin@  s     	V$==&Tl 00>

 <<T[[=YZ ~~h3,,T<{{;)
  	r_  c                 N   U R                  5         U R                  U5      nU R                  U5      nUS   US   U R                  X#5      S.nU R	                  U R                  Xt5      5      nU R                  US0 5      n	U R                  X5      n
U R                  U
UUS.5      $ )a  
create a loan to borrow margin

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

:param str symbol: unified market symbol
:param str code: unified currency code of the currency to borrow
:param str amount: the amount to borrow
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
r<   r  ra  r  )r  r  r  r  %privatePostSpotV1MarginIsolatedBorrowr  rd  r  r  s              r]  borrow_isolated_marginbitmart.borrow_isolated_marginf  s     	V$==&Tl 00>

 ==dkk'>Z[ ~~h3,,T<{{;)
  	r_  c                 X    U R                  USS5      U R                  S U5      S S S S US.$ )N	borrow_idrepay_id)r<   r  r  r  r  r1  ru  )rA  r  )r[  ru  r  s      r]  r  bitmart.parse_margin_loan  s?     $$T;
C//h?
 	
r_  c                 &   U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  US/ 5      nU R	                  US/ 5      nU R                  X5      $ )a  
fetch the rate of interest to borrow a currency for margin trading

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

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

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `isolated borrow rate structures <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
ra  r  )r  r  rd  ry  parse_isolated_borrow_rates)r[  rf  rg  ra  r  s        r]  fetch_isolated_borrow_rates#bitmart.fetch_isolated_borrow_rates  sX     	;;FCB ~~h3..y"5//88r_  fromAccount	toAccountc                    U R                  5         U R                  U5      nU R                  X5      nUUS   S.nU R                  U5      n	U R                  U5      n
US:X  a  US:X  a
  SUS'   XS'   OFUS:X  a  S	US
'   O:US:X  a  US:X  a
  SUS'   XS'   O$US:X  a  SUS
'   O[	        U R
                  S-   5      eSnUS:X  d  US:X  a!  U R                  U R                  X5      5      nO,US:X  d  US:X  a   U R                  U R                  X5      5      nU R                  US0 5      nU R                  U R                  X5      SU R                  U R                  USS5      5      05      $ )aW  
transfer currency internally between wallets on the same account, currently only supports transfer between spot and margin

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

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account to transfer from
:param str toAccount: account to transfer to
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
r<   )r  r  rK   rL   inri  r  rM   spot_to_contractr"  outcontract_to_spotz? transfer() requires either fromAccount or toAccount to be spotNra  rn  r  message)r  r  r  convert_type_to_accountr'   r<   'privatePostSpotV1MarginIsolatedTransferr  $privatePostAccountV1TransferContractrd  parse_transferparse_transfer_statusrA  )r[  r  r  r  r  rf  r  amountToPrecisionr  fromIdtoIdrg  ra  s                r]  r   bitmart.transfer2  s    	==& 66tD' 
 --k:++I6& H$"&$(!f$"4& h&"'$*!&"4#DGG.o$opp8#h)>CCDKKPWD`aHV#f)<@@WA]^H2 ~~h3{{4..t>d001C1CHfV_1`aA
  	r_  c                 2    SSSS.nU R                  X!U5      $ )Nrp  )r   OKFINISHEDr  r  s      r]  r  bitmart.parse_transfer_statusy  s'    

 &99r_  c                 0    SSS.nU R                  X!U5      $ )NrK   rM   r  r  r  r[  r"  typess      r]  parse_transfer_to_account!bitmart.parse_transfer_to_account  $     & &
 T22r_  c                 0    SSS.nU R                  X!U5      $ )NrM   rK   r$  r  r%  s      r]  parse_transfer_from_account#bitmart.parse_transfer_from_account  r)  r_  r   c                    U R                  US5      nU R                  US5      nU R                  US5      UU R                  U5      U R                  X25      U R	                  US5      U R                  U R                  US5      5      U R                  U R                  US5      5      U R                  U R                  US5      5      S.$ )Nr  r  transfer_idr  r"  r  )r<   r  r1  r  r  r  r  rn  )rv  re  r  r  r  r+  r'  r  )r[  r   r  r  r  s        r]  r  bitmart.parse_transfer  s    4 %%h
;
%%h<	""8];"Y///
E&&x:;;D<L<LXW]<^_778H8HSY8Z[001A1A(G1TU	
 		
r_  c                    U R                  5         Uc  SnU R                  USS5      US.nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S	'   U R                  US
5      nU R                  USU5      nU R                  US
/5      nUb  XS'   U R	                  U R                  XT5      5      n	U R                  U	S0 5      n
U R                  U
S/ 5      nU R                  XX#5      $ )a  
fetch a history of internal transfers made on an account, only transfers between spot and swap are supported

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

:param str code: unified currency code of the currency transferred
:param int [since]: the earliest time in ms to fetch transfers for
:param int [limit]: the maximum number of transfer structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.page]: the required number of pages, default is 1, max is 1000
:param int [params.until]: the latest time in ms to fetch transfers for
:returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
Nr   pager   )r1  rB  r<   r  
time_startrB  r  time_endra  r  )	r  re  r  rw  (privatePostAccountV1TransferContractListr  rd  ry  parse_transfers)r[  r  r  rB  rf  r  r  r  r  rg  ra  r  s               r]  fetch_transfersbitmart.fetch_transfers  s    	=E%%ffa8
 }}T*H"*4.GJ$)L!$G!!&'2##FJ>6G9-")J@@WA]^( ~~h3..y"5##GuDDr_  c                 v   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  XGS'   Ub  X7S'   U R	                  U R                  Xu5      5      nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  X5      nU R                  XX45      $ )a]  
fetch the interest owed by the user for borrowing currency for margin trading

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

:param str code: unified currency code
:param str symbol: unified market symbol when fetch interest in isolated markets
:param int [since]: the earliest time in ms to fetch borrrow interest for
:param int [limit]: the maximum number of structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
z1 fetchBorrowInterest() requires a symbol argumentr  r<   r  r  ra  r  )
r'   r<   r  r  *privateGetSpotV1MarginIsolatedBorrowRecordr  rd  ry  parse_borrow_interestsfilter_by_currency_since_limit)r[  r  r  r  rB  rf  r  r  rg  ra  rowsr  s               r]  fetch_borrow_interestbitmart.fetch_borrow_interest  s     >#DGG.a$abbV$fTl
  CL$)L!BB4;;wC_`, ~~h3~~dIr2..t<2285PPr_  c                 `   U R                  US5      nU R                  X25      nU R                  US5      nUU R                  US5      U R                  U R                  US5      5      U R	                  US5      U R	                  US5      U R	                  US5      SUU R                  U5      S.	$ )	Nr  rc  r  interest_amountr  borrow_amountr  )	ru  r  r  r  interestRateamountBorrowedr1  r  r1  )rv  rE  re  r  r  r  )r[  ru  r  rI  r  s        r]  parse_borrow_interestbitmart.parse_borrow_interest#  s     ##D(3!!(3%%dM:	&&vx8//0@0@z0RS((/@A ,,T3DE"..t_E$"Y/

 
	
r_  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xc5      $ )a<  
Retrieves the open interest of a currency

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

:param str symbol: Unified CCXT market symbol
:param dict [params]: exchange specific parameters
:returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
rm  z3 fetchOpenInterest() supports contract markets onlyr  r<   ra  )r  r  r(   r<   #publicGetContractPublicOpenInterestr  rd  parse_open_interestr  s          r]  fetch_open_interestbitmart.fetch_open_interest?  s     	V$j!TWW'\\]]fTl
 ;;DKK<XY ~~h3''55r_  c           	          U R                  US5      nU R                  US5      nU R                  U R                  XB5      U R	                  US5      U R	                  US5      UU R                  U5      US.U5      $ )Nr  r  open_interestopen_interest_value)r  openInterestAmountopenInterestValuer  r1  ru  )re  rv  safe_open_interestr  r  r  )r[  r  r  r  r<   s        r]  rH  bitmart.parse_open_interesta  s     %%h<	h1&&&&r2"&"2"28_"M!%!1!1(<Q!R"Y/(
  	r_  r=  c                 z   Uc  [        U R                  S-   5      eSnU R                  SU5      u  pCU R                  SUSSS/5        U R	                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eUS	   [        U5      US
.nU R                  U R                  Xc5      5      $ )as  
set the level of leverage for a market

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

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'isolated' or 'cross'
:returns dict: response from the exchange
Nz) setLeverage() requires a symbol argumentr   r1  r  r[  rM   z+ setLeverage() supports swap contracts onlyr<   )r  r=  r\  )
r'   r<   r  check_required_argumentr  r  r)   r  (privatePostContractPrivateSubmitLeverager  )r[  r=  r  rf  r1  r  r  s          r]  set_leveragebitmart.set_leverageu  s     >#DGG.Y$YZZ
!??vV
$$]Jz[bNcdV$f~DGG&SSTTTlH#

 <<T[[=YZZr_  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xc5      $ )a@  
fetch the current funding rate

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
rM   z0 fetchFundingRate() supports swap contracts onlyr  r<   ra  )r  r  r)   r<   "publicGetContractPublicFundingRater  rd  parse_funding_rater  s          r]  fetch_funding_ratebitmart.fetch_funding_rate  s     	V$f~DGG&XXYYfTl
 ::4;;w;WX" ~~h3&&t44r_  c           
         Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X6S'   U R	                  U R                  Xd5      5      nU R                  US0 5      nU R                  US/ 5      n	/ n
[        S[        U	5      5       Ht  nX   nU R                  US5      nU R                  XSS	5      nU R                  US
5      nU
R                  UUU R                  US5      UU R                  U5      S.5        Mv     U R!                  U
S5      nU R#                  UUS   X#5      $ )aY  
fetches historical funding rate prices

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

:param str symbol: unified symbol of the market to fetch the funding rate history for
:param int [since]: not sent to exchange api, exchange api always returns the most recent data, only used to filter exchange response
:param int [limit]: the maximum amount of funding rate structures to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
z5 fetchFundingRateHistory() requires a symbol argumentr  r<   rB  ra  r  r   r  rM   funding_timefunding_rate)ru  r  fundingRater  r1  r  )r'   r<   r  r  )publicGetContractPublicFundingRateHistoryr  rd  ry  r  r  rv  r  re  r  r  r  sort_byfilter_by_symbol_since_limit)r[  r  r  rB  rf  r  r  rg  ra  r  ratesr  r  rI  symbolInnerr  sorteds                    r]  fetch_funding_rate_history"bitmart.fetch_funding_rate_history  sR    >#DGG.e$effV$fTl
 $GAA$++gB^_" ~~h3fb1q#f+&AIE''x8H**8S&IK))%@ILL%#//~F& LL3  ' e[1009I5XXr_  c                 z   U R                  US5      nU R                  US5      nU R                  US5      n0 SU_SU R                  X25      _SS _SS _SS _SS _SU_S	U R                  U5      _S
U R	                  US5      _SU_SU R                  U5      _SS _SS _SS _SU R	                  US5      _SS _SS _SS 0E$ )Nr  r  r]  ru  	markPricer@  rB  estimatedSettlePricer1  r_  expected_ratefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRate
rate_valuepreviousFundingTimestamppreviousFundingDatetimeinterval)rv  re  r  r  r  )r[  rm  r  rI  r  rl  s         r]  rY  bitmart.parse_funding_rate  sR    ##Hh7%%h<	,,X~F
H
d&&x8
 
 $	

 D
 #D
 
 Y/
 4++HoF
  0
 t||,<=
 t
 #D
 "4
 "4#3#3Hl#K
  '!
" &t#
$ %
 	
r_  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )au  
fetch data on a single open contract trade position

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

:param str symbol: unified market symbol of the market the position is held in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
r  r<   ra  r   )r  r  !privateGetContractPrivatePositionr  ry  rd  parse_position)r[  r  rf  r  r  rg  ra  firsts           r]  fetch_positionbitmart.fetch_position  s     	V$fTl
 99$++g:VW< ~~h3tQ+""511r_  c                    U R                  5         SnSnUb.  [        U5      nU R                  US5      nU R                  U5      n0 nUS:X  a  US   US'   U R	                  U R                  Xb5      5      nU R                  US/ 5      n/ n	[        S[        U5      5       H%  n
U	R                  U R                  X   5      5        M'     U R                  U5      nU R                  U	SUS5      $ )a  
fetch all open contract positions

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

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
Nr   r   r<   r  ra  F)r  r  rv  r  #privateGetContractPrivatePositionV2r  ry  r  r  ry  rT  filter_by_array_positions)r[  r  rf  r  symbolsLengthrz  r  rg  	positionsr  r  s              r]  fetch_positionsbitmart.fetch_positionsC  s     	LM$$Wa0E[['FA &tGH;;DKK<XY< NN8VR8	q#i.)AMM$--il;< *%%g.--fhOOr_  positionc                    U R                  US5      nU R                  X25      nUS   nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	[        R                  " Xx5      n
[        R                  " Xy5      nU R                  0 SU_SS _SU_SU_S	U R                  U5      _S
S _SS _SUS:X  a  SOS_SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU R                  U5      _SU R                  US5      _SU R                  U	5      _SS _S U R                  U5      U R                  U
5      U R                  US5      U R                  US5      S S S U R                  U5      S S S.E5      $ )Nr  r  position_typemaintenance_margincurrent_valueposition_crossru  r<   r1  lastUpdateTimestampr9  ri  r   longshort	contractscurrent_amountr  
entryPriceentry_priceri  
mark_price	lastPricerh  r=  
collateralinitialMarginunrealized_valuerealized_value)initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentageunrealizedPnlrealizedPnlliquidationPricer1  r   marginRatior5  r6  )	rv  rE  re  r6   
string_divsafe_positionr  r  rZ  )r[  r  r  rI  r  r  ri  r  rh  r  r  r  s               r]  ry  bitmart.parse_position~  s`   . ##Hh7!!(3!%%h<	  ?; ,,X7KL##Ho>%%h0@A
&-&8&89J&U#(():G!! #
H#
$#
 f#
 	#

 Y/#
 "4#
 d#
 tqyFw#
 ))(4DE#
 D,,V^D#
 $**8]C#
 ))(LA#
 #
 ))(3#
 ((:>#
  $++J7!#
" T##
$ (,!%!2!23D!E+/+<+<=X+Y!--h8JK++H6FG $,,[9!#9#
  	r_  c                 &   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   (       d  [	        U R                  S-   5      eSUS   0nUb  X&S'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      nU R                  US/ 5      n/ n	[        S	[        U5      5       H2  n
X   nU R                  US
5      nUS:X  d  M!  U	R                  U5        M4     U R                  XX#5      $ )a2  
retrieves the users liquidated positions

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

:param str symbol: unified CCXT market symbol
:param int [since]: the earliest time in ms to fetch liquidations for
:param int [limit]: the maximum number of liquidation structures to retrieve
:param dict [params]: exchange specific parameters for the bitmart api endpoint
:param int [params.until]: timestamp in ms of the latest liquidation
:returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
z1 fetchMyLiquidations() requires a symbol argumentrM   z1 fetchMyLiquidations() supports swap markets onlyr  r<   r  rr  ra  r   r"  	liquidate)r'   r<   r  r  r.   r  r  r  ry  r  r  rv  r  parse_liquidations)r[  r  r  rB  rf  r  r  rg  ra  r  r  r  checkLiquidations                r]  fetch_my_liquidationsbitmart.fetch_my_liquidations  s    >#DGG.a$abbV$f~tww)\\]]fTl
 $)L!22:wO==dkk'>Z[4 ~~h3q#d)$AGE#//v>;.e$	 %
 &&vuDDr_  c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R                  " XV5      n[        R                  " X5      n	U R	                  UU R                  X25      U R                  U5      U R                  U5      U R                  U5      U R                  U5      U R                  U	5      UU R                  U5      S.	5      $ )Nr  r  r  r  r  )	ru  r  r  r  rN  	baseValue
quoteValuer  r1  )rv  re  r6   rG  safe_liquidationr  rZ  r  )
r[  liquidationr  rI  r  contractsStringcontractSizeStringr  baseValueStringquoteValueStrings
             r]  parse_liquidationbitmart.parse_liquidation  s   & ##K:%%k=A	**;D!--fnE&&{4DE!,,_Q"--oK$$&&x8**?; --.@A&&{3**?;++,<="Y/
&
 
 
	r_  c                    U R                  5         U R                  U5      nUS   (       d!  [        U R                  S-   US   -   S-   5      eU R	                  US5      n	U R	                  US5      n
U R                  U/ SQ5      nU R                  US0 5      nU R                  US	0 5      nU R	                  US
5      nU R	                  US
5      nUSLnU	SLnU
SLnUSLnUSLnUS:H  nSUS   0nU R	                  US5      nUb  U R                  US5      nUUS'   Ub  UUS'   U R                  U/ SQ5      nSnU(       d  U(       d  U(       a-  U R                  USS5      US'   Ub  U R                  X&5      US'   U(       a<  UUS'   U R                  X+5      US'   U R                  U R                  UU5      5      nGOuU(       d  U(       aX  UUS'   U(       a  U R                  X)5      US'   OU R                  X*5      US'   U R                  U R                  UU5      5      nGOU(       d  U(       a~  U(       a+  U R                  USS5      US'   U R                  X.5      US'   O*U R                  USS5      US'   U R                  X/5      US'   U R                  U R                  UU5      5      nOU(       ad  U R                  U5      US'   Ub  U R                  X%5      US'   Ub  U R                  X&5      US'   U R!                  U R                  UU5      5      nO[        U R                  S-   5      eU R                  US0 5      nU R#                  UU5      $ ) a  
edits an open order

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

:param str id: order id
:param str symbol: unified symbol of the market to edit an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float [amount]: how much you want to trade in units of the base currency
:param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.triggerPrice]: *swap only* the price to trigger a stop order
:param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
:param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
:param str [params.stopLoss.triggerPrice]: *swap only* the price to trigger a preset stop-loss order
:param str [params.takeProfit.triggerPrice]: *swap only* the price to trigger a preset take-profit order
:param str [params.clientOrderId]: client order id of the order
:param int [params.price_type]: *swap only* 1: last price, 2: fair price, default is 1
:param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
rM   z editOrder() does not support r"  z) markets, only swap markets are supportedr5  r6  r0  stopLoss
takeProfitr2  NrB  r  r<   r  r  rr  )r2  r1  r5  r6  r  r  rY  r   rX  r2  categorypreset_stop_loss_price_typepreset_stop_loss_pricepreset_take_profit_price_typepreset_take_profit_pricere  rN  zK editOrder() only supports limit, trigger, stop loss and take profit ordersra  )r  r  r.   r<   rv  rC  rd  rw  re  ra  )privatePostContractPrivateModifyPlanOrderr  )privatePostContractPrivateModifyTpSlOrder/privatePostContractPrivateModifyPresetPlanOrderr  r^  *privatePostContractPrivateModifyLimitOrderr  )r[  r<   r  r"  ri  r  rN  rf  r  r5  r6  r2  r  r  presetStopLosspresetTakeProfitr=  r;  r<  isPresetStopLossisPresetTakeProfitrd  r  r  rg  ra  s                             r]  
edit_orderbitmart.edit_order   s   4 	V$f~tww)IIFSYNZ  ^I   I  J  J((A**63DE))&2`a>>&*b9^^FL"=
))(NC++JG%T1"$.
&d2)5-T9fTl
 ((A$YYv7F)6G%&>"$GJ6#~Z<$($5$5flA$NGL! -1-D-DV-S)*"GFO'+'>'>v'TGO$EEdkkRY[aFbcH <"&GJ+/+B+B6+Y(+/+B+B6+[(EEdkkRY[aFbcH !39=9J9J6S_ab9c56484K4KF4c01;?;L;LVUacd;e786:6M6Mf6g23KKDKKX_agLhiH "&"3"3B"7GJ!"&":":6"J #'#:#:6#I FFt{{SZ\bGcdHtww)vvww~~h3f--r_  c                    U R                  5         SnUb  U R                  U5      n0 nU R                  SXd5      u  pdU R                  SSX#U5      nU R	                  U5      nU R                  US/ 5      n	U R                  XX#5      $ )aG  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

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

:param str [code]: unified currency code
:param int [since]: timestamp in ms of the earliest ledger entry
:param int [limit]: max number of ledger entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest ledger entry
:returns dict[]: a list of `ledger structures <https://docs.ccxt.com/#/?id=ledger>`
Nrr  r   ra  )r  r  r  fetch_transactions_request+privateGetContractPrivateTransactionHistoryry  parse_ledger)
r[  r  r  rB  rf  r  r  transactionsRequestrg  ra  s
             r]  fetch_ledgerbitmart.fetch_ledger  s     	}}T*H22:wO"==auU[\CCDWX& ~~h3  >>r_  itemc                    U R                  US5      nS n[        R                  " US5      (       a  Sn[        R                  " SU5      nOSnU R                  US5      nU R	                  XR5      nU R                  US5      nU R                  US5      nU R                  UU R                  US	5      US S U R                  US
5      U R                  U5      US   U R                  U5      UU R                  U5      S S S S S.U5      $ )Nr  r   r  z-1r  assettimer"  tran_idrn  r  )ru  r<   	directionr  referenceAccountreferenceIdr"  r  r  r  r1  r  r  rn  r  )
rv  r6   	string_lerG  r  re  safe_ledger_entryparse_ledger_entry_typerZ  r  )r[  r  r  r  r  r  r  r"  s           r]  parse_ledger_entrybitmart.parse_ledger_entry  s    !!$1	VS))I''f5FI%%dG4
%%j;%%dF3	f-%%""43" $++D)<006 (''/"Y/'
  ! 	r_  c                 6    SSSSSS.nU R                  X!U5      $ )Nr  r`  r   
settlement)zCommission FeezFunding FeezRealized PNLTransferzLiquidation Clearancer  )r[  r"  
ledgerTypes      r]  r  bitmart.parse_ledger_entry_type  s-    # #"%1

 
$77r_  flowTypec                     0 nUb  XS'   S nUb  U R                  U5      nUS   US'   Ub  X6S'   Ub  XFS'   U R                  SXe5      u  peU R                  Xe5      $ )N	flow_typer<   r  r  	page_sizerr  )r  r  r  )r[  r  r  r  rB  rf  r  r  s           r]  r  "bitmart.fetch_transactions_request  s{    #+K [[(F &tGH$)L!#(K 22:wO{{7++r_  c                    U R                  5         SnUb  U R                  U5      n0 nU R                  SXd5      u  pdU R                  SXX45      nU R	                  U5      nU R                  US/ 5      n	U R                  XX#5      $ )a>  
fetch the history of funding payments paid and received on self account

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

:param str [symbol]: unified market symbol
:param int [since]: the starting timestamp in milliseconds
:param int [limit]: the number of entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch funding history for
:returns dict[]: a list of `funding history structures <https://docs.ccxt.com/#/?id=funding-history-structure>`
Nrr  r   ra  )r  r  r  r  r  ry  parse_funding_histories)
r[  r  r  rB  rf  r  r  r  rg  ra  s
             r]  fetch_funding_historybitmart.fetch_funding_history  s     	[[(F22:wO"==aPU^CCDWX& ~~h3++D%GGr_  c           
          U R                  US5      nU R                  US5      nU R                  US5      nUU R                  X2S S5      U R                  U5      UU R	                  U5      U R                  US5      U R                  US5      S.$ )Nr  r  r  rM   r  r  )ru  r  r  r  r1  r<   r  )rv  re  r  r  r  r  )r[  rm  r  rI  r  r  s         r]  parse_funding_historybitmart.parse_funding_history-  s     ##Hh7%%h8
%%h7	&&xvF++J7"Y/""8Y7&&x:
 	
r_  c                     / n[        S[        U5      5       H'  nX   nUR                  U R                  Xr5      5        M)     U R	                  US5      nU R                  XU5      $ )Nr   r  )r  r  r  r  ra  filter_by_since_limit)	r[  r  r  r  rB  r  r  rm  re  s	            r]  r  bitmart.parse_funding_historiesF  s_    q#i.)A |HMM$44XFG * fk2))&??r_  c                    U R                  5         S nUb  U R                  U5      nUS   nU/nU R                  U5      nU R                  US0 5      nU R	                  US/ 5      n	U R                  XS5      n
/ n[        S[        U
5      5       HP  nX   nUS L =(       d    US   U:H  nUS L =(       d    US   U:H  nU(       d  M6  U(       d  M?  UR                  U5        MR     U$ )Nr  ra  r  Fr   noter  )	r  r  &privateGetAccountV1WithdrawAddressListrd  ry  parse_deposit_addressesr  r  r  )r[  r  r  r  rf  codesr  rg  ra  r  allAddresses	addressesr  r  	noteMatchnetworkMatchs                   r]  fetch_withdraw_addresses bitmart.fetch_withdraw_addressesN  s    }}T*HF#DFE>>vF* ~~h3~~dFB/33DG	q#l+,A"oGC76?d+BI'4/WWY5G;5VLy\\  ) - r_  r9  c                     U R                  5         SnU(       a  SnOSnSU0nU R                  U R                  XS5      5      $ )aY  
set hedged to True or False for a market

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

:param bool hedged: set to True to use dualSidePosition
:param str symbol: not used by bingx setPositionMode()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
N
hedge_modeone_way_modeposition_mode)r  )privatePostContractPrivateSetPositionModer  )r[  r9  r  rf  positionModer  s         r]  set_position_modebitmart.set_position_modev  sJ     	'L)L\
 ==dkk'>Z[[r_  c                 |    U R                  U5      nU R                  US5      nU R                  US5      nUUS:H  S.$ )a  
fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets

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

:param str symbol: not used
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an object detailing whether the market is in hedged or one-way mode
ra  r  r  )ru  r9  )(privateGetContractPrivateGetPositionModerd  rv  )r[  r  rf  rg  ra  r  s         r]  fetch_position_modebitmart.fetch_position_mode  sM     @@H ~~h/''o>#|3
 	
r_  c                 B    U R                  5       U R                  S   -
  $ )Nr%  )r  rU  )r[  s    r]  noncebitmart.nonce  s       "T\\2B%CCCr_  r   GETc                 R   UR                  S5      nU R                  USS5      nUS:X  d  US:X  a  SOSn	U R                  U R                  S   U	   5      n
U
S-   U R	                  X5      -   nU R                  X@R                  U5      5      nSnUS:H  =(       d    US	:H  nU(       a   U(       a  U R                  U5      nUS
U-   -  nUS:X  a  U R                  5         [        U R                  5       5      nU R                  U R                  SS5      nU R                  UUSS.nU(       d  U R                  U5      nUnUS-   U R                  -   S-   U-   nU R                  U R!                  U5      U R!                  U R"                  5      [$        R&                  5      nUUS'   XXeS.$ )Nr  r   rK   r  rM   r   r  r  DELETE?r   r,  r#  zapplication/json)zX-BM-KEYzX-BM-TIMESTAMPzX-BM-BROKER-IDzContent-Type#z	X-BM-SIGN)r   methodbodyheaders)r  rv  implode_hostnamer   implode_paramsrw  extract_params	urlencodecheck_required_credentialsr  r  rU  r   jsonr   hmacencoder   hashlibsha256)r[  pathr   r  rf  r  r  r  r  r  baseUrlr   queryqueryStringgetOrDeleter  r,  auth	signatures                      r]  signbitmart.sign  s   

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