
    E#i                    P   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  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!J,r,  S SK-J.r.  S SK/J0r0   " S S\\5      r1g)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntLedgerEntryLeverage	LeveragesMarket
MarketTypeNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)DDoSProtection)ExchangeNotAvailable)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjr0 4S\4S jjrS rS\	S\	4S jr
U 4S	 jrSdS
 jrS r0 4S\\   4S jjrS\S\4S jrS\4S jr0 4S\4S jjrS0 4S\S\S\4S jjrS0 4S\S\	4S jjrSSS0 4S\	S\S\S\\   4S jjrSSS0 4S\	S\S\S\\   4S jjrSSS0 4S\	S\S\S\\   4S jjrSSS0 4S\	S\S\4S jjrS r SeS\S\!S\"4S jjr#SSS0 4S\	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'SeS$\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-SeS)\S\S\)4S* jjr.SeS\S\/4S+ jjr0S,SS0 4S\S-\S\S\S\\/   4
S. jjr1SeS/\S\S\24S0 jjr3S"\	4S1 jr4S2\	4S3 jr5SeS4\S\S\4S5 jjr6SS0 4S\S\S\S\\2   4S6 jjr7S0 4S\S7\8S8\9S\:S9\;4
S: jjr<SS0 4S\S\S7\8S8\9S\;S9\;4S; jjr=S0 4S\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@0 4S@\4SA jjrAS0 4S'\+S\B4SB jjrCSeSC\S\S\D4SD jjrES0 4S'\+S\\F   4SE jjrGSeSF\S\4SG jjrHS0 4S\S\:SH\SI\	S\%4
SJ jjrIS0 4S'\+S\J4SK jjrKSeS\S\L4SL jjrMSSS0 4S\	S\S\4SM jjrNSeS\4SN jjrOS0 4SC\PS\	4SO jjrQS0 4SP\S\	4SQ jjrR0 4S\S\S4SR jjrTSeS\!4SS jjrUS0 4ST\+4SU jjrV0 4SV jrWSS0 4S\S\S\4SW jjrXSeS\4SX jjrYS\PSY\SZ\S[\S\\S]\4S^ jrZS_ r[S`Sa0 SS4Sb jr\Scr]U =r^$ )fbitmex   returnc                   > U R                  [        [        U ]  5       0 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_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+_S0S_S1S_S2S_S3S_E0 S4S+_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_SCS_SDS_E0 SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS+_SMS_SNS_SOS_SPS _SQS_SRS_SSS _STS_SUS_ESSSV.E_SWSXSYSZS[S\._S]S^S^S_.S`SaSaS_.SaSbSc/SdSeSfSg.Sh._SiSj0 SkSl_SmSl_SnSl_SoSl_SpSl_SqSl_SrSl_SsSl_StSl_SuSl_SvSl_SwSl_SxSl_SySl_SzSl_S{Sl_S|Sl_SlSlSlSlSlSlSlSlSlSlSlSlSlSlSlS}.E00 S~Sl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SSl_SlSlSlSlSlSlSlSlSlSlSlSlSlS.E0 S~Sl_SnSl_SsSl_SSl_SSl_SSl_SSl_SSl_SS_SSl_SSl_SS_SS_SSl_SS_SSl_SSl_SlSlSlSlSlSlSlSlSlS.	ESlSS.SSSlS.S.S_._S[        [
        [
        [        [        [        [        [
        S.[        [        [        [        [        [        [
        S.S._S[        _SSlSSSSSSSSSSSSS.
S._SSSSSSS.SSSS SSSSS.SSSSS.S SSS SSS.SSSSS.SSSSSS.SSS SSSSS.SSS S SSSSS.SS0S.	SSSOS00S.SSSOS00S.SS0SS0S.SS0SS0S.S._SSSSSSSSS._5      $ )Nidr-   nameBitMEX	countriesSCversionv1	userAgent	rateLimitd   	certifiedTprohasCORSspotmarginFswapfutureoption	addMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscloseAllPositionsclosePositioncreateOrdercreateReduceOnlyOrdercreateStopOrdercreateTrailingAmountOrdercreateTriggerOrder	editOrderfetchBalancefetchClosedOrdersfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsWithdrawalsemulatedfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchLedgerfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchMarginAdjustmentHistoryfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTransactionsfetchTransferfetchTransfersindexreduceMarginsandboxsetLeverage	setMarginsetMarginModesetPositionMode)transferwithdraw
timeframes1m5m1h1d)r   r   r   r   urlszhttps://testnet.bitmex.com)publicprivatezOhttps://github.com/user-attachments/assets/c78425ab-78d5-49d6-bd14-db7734798f04zhttps://www.bitmex.comz&https://www.bitmex.com/app/apiOverviewzBhttps://github.com/BitMEX/api-connectors/tree/master/official-httpzhttps://www.bitmex.com/app/feesz*https://www.bitmex.com/app/register/NZTR1qg?)urldiscount)testlogoapiwwwdocfeesreferralr   getannouncement   zannouncement/urgentchatzchat/channelszchat/connectedzchat/pinnedfundingguild
instrumentzinstrument/activezinstrument/activeAndIndiceszinstrument/activeIntervalszinstrument/compositeIndexzinstrument/indiceszinstrument/usdVolume	insuranceleaderboard)liquidationzorderBook/L2z
porl/noncequotezquote/bucketedschemazschema/websocketHelp
settlementstatszstats/historyzstats/historyUSDtradeztrade/bucketedzwallet/assetszwallet/networksaddressapiKey	executionzexecution/tradeHistoryglobalNotificationzleaderboard/nameorderzporl/snapshotspositionuserzuser/affiliateStatuszuser/checkReferralCodezuser/commissionzuser/csazuser/depositAddresszuser/executionHistoryzuser/getWalletTransferAccounts)zuser/marginzuser/quoteFillRatiozuser/quoteValueRatiozuser/stakingzuser/staking/instrumentszuser/staking/tierszuser/tradingVolumeuser/unstakingRequestszuser/walletzuser/walletHistoryzuser/walletSummaryuserAffiliates	userEventzguild/archivez
guild/joinz
guild/kickzguild/leavezguild/sharesTrades   zorder/cancelAllAfterzorder/closePositionzposition/isolatezposition/leveragezposition/riskLimitzposition/transferMarginzuser/addSubaccountzuser/cancelWithdrawal)	zuser/communicationTokenzuser/confirmEmailzuser/confirmWithdrawalzuser/logoutzuser/preferenceszuser/requestWithdrawalr   zuser/updateSubaccountzuser/walletTransfer)r   r   )r   z	order/allr   )r   postputdelete
exceptions)zInvalid API Key.zThis key is disabled.zAccess DeniedzDuplicate clOrdIDzorderQty is invalidzInvalid pricezInvalid stopPx for ordTypezAccount is restricted)zSignature not valid
overloadedz*Account has insufficient Available BalancezService unavailablezServer Error,Unable to cancel order due to existing statez$We require all new traders to verify)exactbroadprecisionModeoptionsbtcethbsctronavaxnearxtzdotsolada)
BTCERC20BEP20TRC20AVAXCNEARXTZDOTSOLADA)api-expiresfetchOHLCVOpenTimestampoldPrecisionnetworksfeatures)lastmark)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingmarketBuyRequiresPricemarketBuyByCost  i@B )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   r   i'  )	r~   rK   createOrdersrj   rm   rl   ro   rR   rk   defaultr   )extendsrK   r   derivatives)linearinverse)r   r?   r   rA   rB   commonCurrenciesUSDTr   ETHr   )USDtXBtXBTGweiGWEILAMPLAMp)deep_extendsuperr-   describer    r!   r&   r)   r%   r   r*   )self	__class__s    S/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/bitmex.pyr   bitmex.describe   s5
   fd < > zA
(zA
HzA
 $zA
 t	zA

 zA
 zA
 zA
 4zA
  GGG %G 	G
 $G %G TG "4G 'G tG G $UG  G tG (G  "4!G" ,T#G$ %d%G& T'G( )G* $T+G, "4-G. &t/G0 (1G2 1%3G4 +J5G6 *:7G8 +D9G: &u;G< #J=G> *4?G@ $TAGB "5CGD tEGF  GGH !$IGJ %eKGL $TMGN /OGP +EQGR SGT !%UGV &uWGX  YGZ d[G\ "4]G^ d_G` !$aGb tcGd  eGf 'gGh !$iGj (kGl %emGn )%oGp tqGr sGt tuGv $ZwGx  yGz !%{G| }G~ G@ 4AGB tCGD TEGF  GGH "5IGJ " MGzA
j 	kzA
v :; j67 0<X :G #!wzA
`  !&!-q! ! (	!
 )!! &q! "1!  ! %a! ,Q! 6q! 5a! 4Q! -a! /!  $Q!!" &q#!$ ()()&'!"*+"#01&'!")*,-!"*+)*+,A!#J!1 ! $Q 1!	
 -a +A   )! #A  / 1! *1 #A .q  0!" 9!#$ ()/001()45././23'(././*+%&=@!1   (	
 %a %a &q -a   / .q +A ,Q -a 21  -a!" 0#$ 45-.23'(,-232312/05: "#!"
 "#%&23CFKlazA
z (;-=%5)5+7%12>-=	 ,?"6BS+?$1DP<L{zA
d YezA
f   !+/ % ""##"    gzA
L #&*(,$($(- -1).+06:#'#'"&#(	( #($(27+0)$6 %)&+!$$(%,*/& ',#($)*/	# ',!$#($)*/( ',!$$(%,#($)*/$ ',!$$(,0%,#($)*/	*  #KHT  )*#U-$  )*#T-$  "= "= 	 "= "= 	EjMzA
b !czA
 z z	    c                 x  #    U R                  U5      I Sh  vN n0 n[        S[        U5      5       GH}  nX$   nU R                  US5      nU R	                  U5      nU R                  US5      nU R                  US5      n	U R                  US/ 5      n
SnSn0 nU R                  US5      nU R                  U5      nU R                  U5      n[        S[        U
5      5       H  nU
U   nU R                  US5      nU R                  U5      nU R                  US	5      nU R                  [        R                  " UU5      5      nU R                  US
S5      nU R                  USS5      nU=(       a    UnU(       a  SnU(       a  SnUUUUUUUSSSS.SSS.S.S.	UU'   M     U R                  US5      nU=(       d    U=(       d    UnU R                  US5      nU R                  [        R                  " UU5      5      nU R                  US5      nU R                  [        R                  " UU5      5      nU R                  US5      n U R                  [        R                  " U U5      5      n!U R                  US5      S:H  n"UUUU	UUUSUSSS.UUS.U!SS.S.UU"(       a  SOSS.X7'   GM     U$  GN7f)z
fetches all available currencies on an exchange

https://www.bitmex.com/api/explorer/#not /Wallet/Wallet_getAssetsConfig

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
Nr   assetcurrencyr2   r   FscalewithdrawalFeedepositEnabledwithdrawalEnabledTminmax)r   deposit)	infor1   networkactiver  r   fee	precisionlimitsenabledminWithdrawalAmountmaxWithdrawalAmountminDepositAmountcurrencyTypeCrypto)amountr   r  cryptoother)r1   coder  r2   r  r  r   r  r  r  r   type)publicGetWalletAssetsrangelensafe_stringsafe_currency_code
safe_valueparse_precisionparse_numbernetwork_id_to_coder+   
string_mul	safe_bool)#r   paramsresponseresultir  r  r  r1   r2   chainsr	  withdrawEnabledr   r  precisionStringr  jchain	networkIdr  withdrawalFeeRawr  isDepositEnabledisWithdrawEnabledr  currencyEnabledcurrencyActiveminWithdrawalStringminWithdrawalmaxWithdrawalStringmaxWithdrawalminDepositString
minDepositisCryptos#                                      r  fetch_currenciesbitmex.fetch_currencies  s     33F;;D q#h-(A{H$$Xw7E**51D!!(J7B##Hf5D__Xz2>F"N#OH$$Xw7E"2259O))/:I1c&k*q	 ,,UG<	11)<#'#3#3E?#K  $ 1 1'2D2DEUWf2g h#'>>%9I5#Q $(NN5:Mu$U!*@/@#%)N$&*O!#&$/ 1(!% $(#'%
 $(#'$	%! +B #ooh	BO,S1R?N"&"2"28=R"S --g.@.@ATVe.fgM"&"2"28=R"S --g.@.@ATVe.fgM#//:LM**7+=+=>NP_+`aJ''.AXMH ()+&  $#
  -,!
  *#  %$,'3FLo )d k <s   J:J7J J:c                     U R                  U5      nU R                  US5      nU R                  U5      n[        R                  " XT5      nU R                  U5      $ Nr  )r  r#  number_to_stringr+   
string_divr'  )r   r  r  r  r  amountStringfinalAmounts          r  convert_from_real_amountbitmex.convert_from_real_amount  sS    ==&$$X{;	,,V4((A  --r  r  r  c                     Uc  U$ Uc  g U R                  U5      nU R                  US5      n[        R                  " X$5      $ rD  )r  r#  r+   r)  )r   r  r  r  r  s        r  convert_to_real_amountbitmex.convert_to_real_amount   sE    <M^==&$$X{;	!!&44r  c                    > U R                  U5      nU R                  U5      nU R                  U R                  S5      nUS   (       a  U(       d  U R	                  US   U5      n[
        [        U ]  X5      $ )Nr   r?   base)safe_symbolmarketr%  r   rI  r   r-   amount_to_precision)r   symbolr  rQ  r   r   s        r  rR  bitmex.amount_to_precision)  sf    !!&)V$t||^D&>,226&>6JFVT6vFFr  c                    U R                  U R                  S5      (       a  U R                  U5      $ U R                  U5      nU R	                  XR
                  5      nU(       d  U R                  U5      $ U R                  U5      nUS   (       a#  U R                  U R                  XS   U5      5      $ U R                  U5      $ )Nr   r?   )r%  r   r'  rP  in_arraysymbolsrQ  rL  )r   rS  rawQuantitycurrencySidemarketExistsrQ  s         r  convert_from_raw_quantity bitmex.convert_from_raw_quantity1  s    ??4<<88$$[11!!&)}}V\\:$$[11V$&>$$T%@%@AUWb%cdd  --r  c                 &    U R                  XS5      $ )Nr   )r[  )r   rS  rX  s      r  convert_from_raw_costbitmex.convert_from_raw_cost=  s    --f7KKr  c                 b   #    U R                  U5      I Sh  vN nU R                  U5      $  N7f)a  
retrieves data on all markets for bitmex

https://www.bitmex.com/api/explorer/#not /Instrument/Instrument_getActive

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
N)publicGetInstrumentActiveparse_markets)r   r+  r,  s      r  fetch_marketsbitmex.fetch_markets@  s5      77??` !!(++a @s   /-/rQ  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5      nU R                  US5      nSnSn	Sn
US:X  a  SnS	nO4US
:X  a  SnS	n	O)US:X  a  SnS	n
OUS:X  a  UnU R                  US5      nSnS	n
U R                  U5      nU R                  U5      nU=(       d    U
nS nU R                  US5      nU R                  US5      nU(       a  U(       + =(       a    U(       + OS nU R                  US5      nUS:H  nS nS nS nU	(       a	  US-   U-   nOU(       a  US-   U-   S-   U-   nU(       a:  U R                  USS5      nU R	                  [
        R                  " SU5      5      nO7[
        R                  " U R                  US5      5      nU R	                  U5      nU R                  US5      nU R                  U5      nUb  US-   U R                  U5      -   nOUnU R                  USS5      nU R                  U5      nUU:H  nU R                  US5      nU R                  USS5      nU R	                  [
        R                  " SU5      5      nU	(       a  S nS nS n0 SU_SU_S U_S!U_S"U_S#U_S$U_S%U_S&W_SU	_S'S_SU_SU
_S(S_S)U_S*U_S+U_UUU R                  US,5      U R                  US-5      UUUU R                  US.5      S U R                  US/5      U R                  US05      S1.U(       a  U R	                  S5      OS U(       a  UOS S2.S U(       a  S OUS2.S U R                  US35      S2.S U(       a  UOS S2.S4.S US5.E$ )6NrS  
underlyingquoteCurrencysettlCurrencytypFFFWCSXrA   TIFXXXPr?   FFCCSXrB   FFICSX
rootSymbol	isInverseisQuantostateOpen/:underlyingToPositionMultiplierunderlyingToSettleMultiplier1
multiplierexpiry-positionCurrencymaxOrderQty
initMarginr1   rO  r   settlebaseIdquoteIdsettleIdr  r@   rC   r  contractr   takerFeemakerFeeoptionStrikePricelotSizetickSize)r  pricer  maxPrice)leverager  r  cost)r   quantotakermakercontractSizery  expiryDatetimestrike
optionTyper  r  createdr  )r#  r$  r%  safe_string_2r'  r+   rF  
string_abs	parse8601yymmddsafe_number)r   rQ  r1   r  r  r  r~  ri  rA   r?   rB   r  rO  r   r  r  ro  rp  r   statusr  ry  r  rS  multiplierString
positionIdr   positionIsQuoter|  r}  maxLeverages                                  r  parse_marketbitmex.parse_market  sk   fh/!!&,7""6?;##FO<((2 vu-(?DDH_DDH_DFH_G%%fl;FDF&&v.''0>6OOFK8	??6:65=i-0L4!!&'26!CZ%'FCZ%'#-6F#'#5#5f>^`~# #001C1CCIY1Z[#*#5#5d6F6Fv|6\#] #001AB!--fh?N^^N3F!#F(;; F''0BLQ
**:6#u,&&v}=%%flC@
''(:(:3
(KLIHF3
"3
f3
 D3
 U	3

 f3
 f3
 w3
 3
 D3
 D3
 e3
 D3
 f3
 e3
 f3
  !3
" f#3
$ !%%fj9%%fj9(,&&v/BC**69=))&*= 6>4,,S14*2;
  #24
  ++FJ?
  *9;t$ e3
 3	
r  c                 r   SU0n[        S[        U5      5       H  nX   nU R                  US5      nU R                  U5      nU R	                  5       nU R                  US5      nU R                  US5      n	U R                  Xh5      US'   U R                  Xi5      US'   XrU'   M     U R                  U5      $ )Nr  r   r  availableMarginmarginBalancefreetotal)r!  r"  r#  r$  accountrL  safe_balance)
r   r,  r-  r.  balance
currencyIdr  r  r  r  s
             r  parse_balancebitmex.parse_balance4  s    ` )q#h-(AkG))':>J**:6DllnG##G->?D$$Wo>E"99$EGFO#::4GGG"4L )   ((r  c                    #    U R                  5       I Sh  vN   SS0nU R                  U R                  X!5      5      I Sh  vN nU R                  U5      $  NA N7f)aA  
query for balance and get the amount of funds available for trading or funds locked in orders

https://www.bitmex.com/api/explorer/#not /User/User_getMargin

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr  all)load_marketsprivateGetUserMarginextendr  )r   r+  requestr,  s       r  fetch_balancebitmex.fetch_balanceq  sc      !!!
 224;;w3OPP` !!(++i 	" Qs!   AA+AAAANrS  r   c                 @  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X%S'   U R                  U R                  XS5      5      I Sh  vN nU/ / SSSS.n[	        S[        U5      5       Hb  nXh   n	U	S   S:X  a  S	OS
n
U R                  XR                  U	S5      5      nU R                  U	S5      nUc  ML  Xz   nUR                  X/5        Md     U R                  US
   SS5      US
'   U R                  US	   S5      US	'   U$  GN N7f)a	  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.bitmex.com/api/explorer/#not /OrderBook/OrderBook_getL2

: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
NrS  r1   depth)rS  bidsasks	timestampdatetimenoncer   sideSellr  r  sizer  T)r  rQ  publicGetOrderBookL2r  r!  r"  r[  r#  r  appendsort_by)r   rS  r   r+  rQ  r  r,  r-  r.  r   r  r  r  
resultSides                 r  fetch_order_bookbitmex.fetch_order_book  s?     !!!V$fTl
 $G224;;w3OPP
 q#h-(AKE#Fmv56FD33F<L<LUTZ<[\F$$UG4E  #\
!!5/2 ) fVna>vfVna8v; 	" Qs*   DDADDA*DADDr1   c           	         #    SSU00nU R                  USSU R                  XC5      5      I Sh  vN n[        U5      nUS:X  a  US   $ [        U R                  S-   U-   S-   5      e N87f)au  
fetches information on an order made by the user

https://www.bitmex.com/api/explorer/#not /Order/Order_getOrders

:param str id: the order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
filterorderIDNr   r   z: The order z not found.)fetch_ordersr   r"  r'   r1   )r   r1   rS  r+  r  r,  
numResultss          r  fetch_orderbitmex.fetch_order  s      2

 **64t?O?OPV?_``]
?A;DGGn4r9MIJJ	 as   -A*A(9A*sincec                 d  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4S5      I Sh  vN $ Sn0 nUb  U R                  U5      nUS   US'   Ub  U R	                  U5      US'   Ub  X7S	'   U R                  US
S5      nUb'  U R                  US
/5      nU R	                  U5      US'   U R                  Xt5      nSU;   a  U R                  US   5      US'   U R                  U5      I Sh  vN n	U R                  XX#5      $  GN N N7f)a(  

https://www.bitmex.com/api/explorer/#not /Order/Order_getOrders

fetches information on multiple 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]: the earliest time in ms to fetch orders for
:param boolean [params.paginate]: 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 Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NFro   paginater:   r1   rS  	startTimecountuntilendTimer  )r  handle_option_and_paramsfetch_paginated_call_dynamicrQ  iso8601safe_integer_2omitr   jsonprivateGetOrderparse_orders
r   rS  r  r   r+  r  rQ  r  r  r,  s
             r  r  bitmex.fetch_orders  sO     !!!88PZ[::=&Y^hklll[[(F &tGH#'<<#6GK $G##FGY?YYvy1F!%e!4GI""73 w $		'(*; <GH--g66  5@@3 	" m( 7s4   D0D)9D0D,CD0D.D0,D0.D0c           	      l   #    SSS00nU R                  XX0R                  XT5      5      I Sh  vN $  N7f)a  
fetch all unfilled currently open orders

https://www.bitmex.com/api/explorer/#not /Order/Order_getOrders

: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 orders structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r  openTN)r  r   )r   rS  r  r   r+  r  s         r  fetch_open_ordersbitmex.fetch_open_orders  sA      

 &&ve=M=Mg=^____s   +424c                 n   #    U R                  XX45      I Sh  vN nU R                  USSS/S5      $  N7f)a  
fetches information on multiple closed orders made by the user

https://www.bitmex.com/api/explorer/#not /Order/Order_getOrders

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr  closedcanceledF)r  filter_by_array)r   rS  r  r   r+  orderss         r  fetch_closed_ordersbitmex.fetch_closed_orders,  s>      ((FF##FHx6LeTT Gs   535c                 z  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4S5      I Sh  vN $ Sn0 nUb  U R                  U5      nUS   US'   Ub  U R	                  U5      US'   Ub  [        S	U5      US
'   U R                  USS5      nUb'  U R                  US/5      nU R	                  U5      US'   U R                  Xt5      nSU;   a  U R                  US   5      US'   U R                  U5      I Sh  vN n	U R                  XX#5      $  GN N N7f)a  
fetch all trades made by the user

https://www.bitmex.com/api/explorer/#not /Execution/Execution_getTradeHistory

: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 boolean [params.paginate]: 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 Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
NFrj   r  r:   r1   rS  r  r   r  r  r  r  )r  r  r  rQ  r  r  r  r  r   r  privateGetExecutionTradeHistoryparse_tradesr  s
             r  fetch_my_tradesbitmex.fetch_my_trades<  s\     !!!88R\]::?F[`jmnnn[[(F &tGH#'<<#6GK "3GG##FGY?YYvy1F!%e!4GI""73 w $		'(*; <GH==gFFl   5@@] 	" o( Gs4   D;D49D;D7CD;D9D;7D;9D;c                 :    SSSSSSSS.nU R                  X!U5      $ )Ntransactionr@   r   r   r   )
WithdrawalRealisedPNLUnrealisedPNLDepositTransferAffiliatePayout	SpotTrader#  )r   r  typess      r  parse_ledger_entry_typebitmex.parse_ledger_entry_type  s3    '#%$") 
 T22r  itemr  c                 l   U R                  US5      nU R                  US5      nU R                  US5      nS nU R                  U R                  US5      5      nU R                  US5      nU R                  X5      n	U R                  X5      nU R                  US5      n
U R	                  X5      nU R                  U R                  US5      5      nUc  SnS nU R                  US	5      nUb%  U R	                  X5      nU R                  U5      U	S
.nU R                  US5      nUb  U R	                  X5      nU R                  [        R                  " U R                  U5      U R                  U5      5      5      nS n[        R                  " U
S5      (       a)  SnU R	                  U	[        R                  " U
5      5      nOSnU R                  U R                  US5      5      nU R                  UUUU R                  U5      UUUUUU	U R                  U5      UU R                  U5      UUS.U5      $ )N
transactIDr  txtransactTyper  r  transactTimer   r  )r  r  walletBalance0outintransactStatus)r  r1   r  r  	directionr  referenceIdreferenceAccountr  r  r  beforeafterr  r  )r#  r  r$  safe_currencyrL  r  r'  r+   
string_subrE  	string_ltr  parse_transaction_statussafe_ledger_entryr  )r   r  r  r1   r  r  r  r  r  r  rG  r  r  r  feeCostr  r  r  r  s                      r  parse_ledger_entrybitmex.parse_ledger_entry  sD   T dL1""43&&tT2++D,<,<T>,RS%%dJ7
&&z<%%j;''h7,,T@NN4#3#3D.#IJ	 I""4/11$@G))'2 C   7//<E""7#5#5d6K6KE6RTXTiTijpTq#rs	\3//I00w7I7I,7WXFI..t/?/?FV/WX%%"Y/"& 0''/&&u-'
  ! 	r  c                   #    U R                  5       I Sh  vN   0 nUb  X5S'   SnUb  U R                  U5      nUS   US'   U R                  U R                  XT5      5      I Sh  vN nU R	                  XvX#5      $  Ne N7f)a   
fetch the history of changes, actions done by the user or operations that altered the balance of the user

https://www.bitmex.com/api/explorer/#not /User/User_getWalletHistory

:param str [code]: unified currency code, default is None
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
:param int [limit]: max number of ledger entries to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
Nr  r1   r  )r  r  privateGetUserWalletHistoryr  parse_ledger)r   r  r  r   r+  r  r  r,  s           r  fetch_ledgerbitmex.fetch_ledger  s      !!!
 $G}}T*H"*4.GJ99$++g:VWW*   UBBI 	" Xs"   B A<AB %A>&B >B c                 4  #    U R                  5       I Sh  vN   SS0nSnUb  U R                  U5      nUS   US'   Ub  X5S'   U R                  U R                  XT5      5      I Sh  vN nU R	                  USSS/S	5      nU R                  XX#5      $  N} N.7f)
a3  
fetch history of deposits and withdrawals

https://www.bitmex.com/api/explorer/#not /User/User_getWalletHistory

:param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
:param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
:param int [limit]: max number of deposit/withdrawals to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr  r  r1   r  r  r  r  F)r  r  r  r  r  parse_transactions)	r   r  r  r   r+  r  r  r,  transactionss	            r  fetch_deposits_withdrawals!bitmex.fetch_deposits_withdrawals6  s      !!!
 }}T*H"*4.GJ$G99$++g:VWW++Hn|U^F_afg&&|uLL% 	"  Xs"   BBAB'B(-BBr  c                 4    SSSSS.nU R                  X!U5      $ )Npendingr  ok)	ConfirmedCanceled	CompletedPendingr  r   r  statusess      r  r  bitmex.parse_transaction_statusV  s*    "" 	
 &99r  r  c                 (   U R                  US5      nU R                  X25      nU R                  U R                  US5      5      nU R                  U R                  US5      5      nU R                  US5      nS nS nS n	US:X  a'  U R                  US5      nU R                  US5      nUn	O*US:X  a$  U R                  US5      n	U R                  US5      nU R                  US	5      n
[        R
                  " U
5      nU R                  US
   U5      nU R                  US5      nU R                  US
   U5      nU R                  US5      nUb  U R                  U5      n0 SU_SU R                  US5      _SU R                  US5      _SU_SUS
   _SU R                  U R                  US5      US
   5      _S	U R                  U5      _SU_SU_SU R                  U5      _SU_SU_SU	_SS _SS _SS _SU_S S US
   U R                  U5      S S.S.E$ )Nr  r  r  r  
withdrawalr   r  r  r  r  r  r  r  r1   r  txidr  r  r  r  addressFrom	addressTotagtagFromtagToupdated)r  r  rate)internalcommentr  )r#  r  r  safe_string_lowerr+   r  rL  r  r(  r'  r  )r   r  r  r  r  r  r  r   r'  r(  rG  amountStringAbsr  feeCostStringr  r  s                   r  parse_transactionbitmex.parse_transaction_  s   ( %%k:>
%%j; ~~d&6&6{N&STNN4#3#3K#MN	%%k>B	<&&{I>G**;=KIY((i@I**;=K''X>!,,\:,,Xf-=O((e<--hv.>N!!+/?@226:F
K
$"";=
 D$$[$7
 D	

 (
 t..t/?/?Y/WYabhYij
 d''/
 f
 
 \2
 w
 ;
 
 4
 t
  T!
" y#
$ $V,))'2)
 	
r  c                 J  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US5      nUc  [        U R                  S-   U-   S-   5      eU R                  Xc5      $  N NJ7f)a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://www.bitmex.com/api/explorer/#not /Instrument/Instrument_get

: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>`
NrS  r1   r   z fetchTicker() symbol z
 not found)r  rQ  publicGetInstrumentr  r%  r$   r1   parse_ticker)r   rS  r+  rQ  r  r,  tickers          r  fetch_tickerbitmex.fetch_ticker  s      !!!V$fTl
 11$++g2NOO1->DGG&>>G,VWW  00 	"
 Ps"   B#B?B#B!A	B#!B#rW  c                 T  #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      I Sh  vN n0 n[        S[	        U5      5       H1  nU R                  X5   5      nU R                  US5      nUc  M-  XdU'   M3     U R                  USU5      $  N Ne7f)a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://www.bitmex.com/api/explorer/#not /Instrument/Instrument_getActiveAndIndices

: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   rS  )r  market_symbols#publicGetInstrumentActiveAndIndicesr!  r"  r7  r#  filter_by_array_tickers)r   rW  r+  r,  r-  r.  r8  rS  s           r  fetch_tickersbitmex.fetch_tickers  s      !!!%%g.AA&IIq#h-(A&&x{3F%%fh7F!!'v	 )
 ++FHgFF 	"Is(   B(B$)B( B&AB(	B(&B(r8  c           	         U R                  US5      nU R                  X25      nU R                  U R                  US5      5      nU R                  US5      nU R                  US5      nU R                  0 SU_SU_SU R	                  U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S5      _SS _SU R                  US5      _SU_SU_SU_SS _SS _SS _SS _U R                  US5      U R                  US5      U R                  US5      US.EU5      $ )NrS  r  prevPrice24h	lastPricer  high	highPricelowlowPricebidbidPrice	bidVolumeaskaskPrice	askVolumevwapr  closer   previousClosechange
percentageaveragehomeNotional24hforeignNotional24h	markPrice)
baseVolumequoteVolumerV  r  )r#  rP  r  safe_tickerr  )r   r8  rQ  marketIdrS  r  r  r   s           r  r7  bitmex.parse_ticker  s   ##FH5!!(3NN4#3#3FK#HI	74 !
f!
!
 Y/!
 D$$V[9	!

 4##FJ7!
 4##FJ7!
 !
 4##FJ7!
 !
 D$$VV4!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **63DE++F4HI))&+>+!
, - 	r  c                 `   U R                  US5      nU R                  X25      nU R                  US   U R                  US5      5      nU R                  U R                  US5      5      U R	                  US5      U R	                  US5      U R	                  US5      U R	                  US5      U/$ )NrS  volumer  r  rD  rF  rO  )r#  safe_marketr[  r  r  )r   ohlcvrQ  rZ  r]  s        r  parse_ohlcvbitmex.parse_ohlcv  s    $ ##E84!!(3//x0@$BRBRSXZbBcdNN4++E;?@UF+UF+UE*UG,
 	
r  r   	timeframec                 `  #    U R                  5       I Sh  vN   SnU R                  USS5      u  peU(       a  U R                  SXXBU5      I Sh  vN $ U R                  U5      nUS   U R	                  U R
                  X"5      SS.nUb  XHS'   U R                  US	5      n	U	b'  U R                  US	/5      nU R                  U	5      US
'   U R                  U5      S-  n
U R                  U R                  SS5      nUb0  UnU(       a  U R                  X5      nU R                  U5      nXS'   OSUS'   U R                  U R                  X5      5      I Sh  vN nU R                  XX#U5      nU(       a-  [!        S[#        U5      5       H  nUU   S   U
-
  UU   S'   M     U$  GN GNY NS7f)a?  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://www.bitmex.com/api/explorer/#not /Trade/Trade_getBucketed

: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 boolean [params.paginate]: 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
NFrk   r  r1   T)rS  binSizepartialr  r  r    r   r  reverser   )r  r  "fetch_paginated_call_deterministicrQ  r#  r   safe_integerr  r  parse_timeframer*  r   sumpublicGetTradeBucketedr  parse_ohlcvsr!  r"  )r   rS  rb  r  r   r+  r  rQ  r  r  durationr   r  r  r,  r-  r.  s                    r  fetch_ohlcvbitmex.fetch_ohlcv  s     !!!88zZ@@v^cpvwww V$Tl''N	
 $G!!&'2YYvy1F!%e!4GI''	2T9"&..?XZ^"_I& HHY9	Y/I#,K !%GI44T[[5QRR ""8YuM" 1c&k*%ay|h6q	! +m 	" xF Ss5   F.F&9F.F)DF.F,AF.)F.,F.r   c                    U R                  US5      nU R                  X25      nU R                  U R                  US5      5      nU R                  USS5      nU R	                  X@R                  USS5      5      nU R                  U R                  X@R                  US5      5      5      nU R                  US5      n	U R                  US	5      n
U R                  US
5      nS nU R                  U R                  X@R                  US5      5      5      nUb8  U R                  USS5      nUU R                  U5      U R                  US5      S.nU R                  US5      nS nUb&  US:X  a   [        R                  " US5      (       a  SOSnU R                  US5      nU R                  UUU R                  U5      UU	U
UUUU[        R                  " U5      UUS.U5      $ )NrS  r  avgPxr  r  lastQtyexecCost
trdMatchIDr  r  execCommrh  r  
commission)r  r  r-  execTyper   r  r  r  ordType)r  r  r  rS  r1   r   r  takerOrMakerr  r  r  r  r  )r#  rP  r  r  r[  rE  r^  r0  r$  r+   r
  
safe_trader  r  )r   r   rQ  rZ  rS  r  priceStringrG  rt  r1   r   r  r  r2  r  rx  rz  r  s                     r  parse_tradebitmex.parse_tradeV  s   J ##E84!!(3NN4#3#3E;#GH	((A55f>P>PQVX^`i>jk(()C)CFL\L\]bdnLo)pqe\2  	2%%eV4--d.H.HQaQabgisQt.uv$++E?JOJ% 33J?((=C ##E:6$W)<&-&7&7s&K&K7QXL%%eY7"Y/( &&x0" 
  	r  c                 D    SSSSSSSSSSSSS.nU R                  X!U5      $ )Nr  r  r  rejectedexpired)NewPartiallyFilledFilled
DoneForDayr  PendingCancel
PendingNewRejectedExpiredStoppedUntriggered	Triggeredr  r!  s      r  parse_order_statusbitmex.parse_order_status  sB    % "# " !
 &99r  r   c                 4    SSSSS.nU R                  X!U5      $ )NDayGTCr   r   )r  GoodTillCancelImmediateOrCancel
FillOrKillr  )r   r   timeInForcess      r  parse_time_in_forcebitmex.parse_time_in_force  s*    #!&	
 ;GGr  r   c           
         U R                  US5      nU R                  X25      nUS   nU R                  US5      nS nS nSnUc#  U R                  U R                  SS5      n	U	S:H  nOU R                  USS5      nU(       a  U R	                  XE5      nOU R	                  XE5      nU R                  US5      n
S nU R                  U R	                  X@R                  US5      5      5      nU(       a  [        R                  " X5      nOUnU R                  US	5      nS nUb  US
:H  nU R                  U R                  US5      5      nU R                  US5      nU R                  US5      nU R                  0 SU_SU R                  US5      _SU R                  US5      _SU_SU R                  U5      _SU R                  U R                  US5      5      _SU_SU R                  US5      _SU R                  U R                  US5      5      _SU_SU R                  US5      _SU R                  US5      _SU_SU_SU_SU
_S U_U R	                  UU5      U R                  U R                  US!5      5      S S S".EU5      $ )#NrS  orderQtyFdefaultSubTyper   r   rr  cumQtyexecInstParticipateDoNotInitiater  stopPx	leavesQtyr  r1   r  clientOrderIdclOrdIDr  lastTradeTimestampr  r  ry  r   postOnlyr  r  r   r  r  rS  filled	ordStatus)	remainingr  r  trades)r#  r^  r   r*  r[  rE  r+   rF  r  r  
safe_orderr  r0  r  r  )r   r   rQ  rZ  rS  qtyr  r  ro  r  rS  r  r  r  r  r  r   r  s                     r  parse_orderbitmex.parse_order  s   L ##E84!!(3!uj1	!--dll<LhWN'94Ivy%@I11&>D33F@F""5'2&&t'E'EfN^N^_dfnNo'pq''8FF##E:6 $>>HNN4#3#3E;#GH	''x8$$UK8	  
E 
$""5)4 
 T--eY? 
 	 

 Y/ 
 !$..1A1A%1X"Y 
 f 
 D**5)< 
 433D4D4DUM4Z[ 
  
 D**5&9 
 T%%eW5 
 L 
 f 
 D 
  w! 
" f# 
$ 77	J--d.>.>uk.RS+ 
, - 	r  c                 4  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ U R                  U5      nSUS   0nUb  U R	                  U5      US'   OSUS	'   Ub  [        US
5      US'   U R                  USS5      nUb'  U R                  US/5      nU R	                  U5      US'   U R                  U R                  Xt5      5      I Sh  vN n	U R                  XX#5      $  N N N7f)a  
get the list of most recent trades for a particular symbol

https://www.bitmex.com/api/explorer/#not /Trade/Trade_get

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.paginate]: 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 Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
NFrx   r  rS  r1   r  Trg  rf  r  r  r  )r  r  r  rQ  r  r  r  r  publicGetTrader  r  r  s
             r  fetch_tradesbitmex.fetch_trades:  s0     !!!88PZ[::=&Y^gggV$fTl
 #'<<#6GK  "&GI"5$/GG##FGY?YYvy1F!%e!4GI,,T[[-IJJ:   5@@c 	" h  Ks4   DD8DDB+D;D<DDDr  r  r  c                 .  #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      nU R                  US5      n	U	b5  US   (       d+  US   (       d!  [	        U R
                  S-   US   -   S-   5      eU R                  U R                  SS	5      n
U R                  U R                  X5      5      nUS
   U R                  U5      UUU
S.nU R                  U/ SQ5      nU R                  USS5      nUSLnUSLnU(       d  U(       GaV  U R                  US5      nUS:H  =(       d    US:H  nUS:X  d  US:X  a  U R                  SUSSS/5        US:X  a  US:X  a  U(       a  SOSnO/U(       a  SOSnO#US:X  a  US:X  a  U(       a  SOSnOU(       a  SOSnU(       ag  US:H  =(       a    US:H  =(       d    US:H  nUS:H  =(       a    US:H  =(       d    US:H  nU(       d  U(       a  SU-   nU R                  U5      US'   SUS'   ODUc  [        U R
                  S-   U-   S -   5      eU R                  U R                  X5      5      US!'   XS"'   U R!                  U/ S#Q5      nUS$:X  d  US:X  d  US:X  a#  U R                  U R                  X5      5      US%'   U R                  US&S'5      nUb  UUS&'   U R!                  US&S'/5      nU R#                  U R%                  X5      5      I Sh  vN nU R'                  UU5      $  GN N7f)(a  
create a trade order

https://www.bitmex.com/api/explorer/#not /Order/Order_new

: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 dict [params.triggerPrice]: the price at which a trigger order is triggered at
:param dict [params.triggerDirection]: the direction whenever the trigger happens with relation to price - 'ascending' or 'descending'
:param float [params.trailingAmount]: the quote amount to trail away from the current market price
:returns dict: an `order structure <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
N
reduceOnlyrA   rB   z/ createOrder() does not support reduceOnly for r  zI orders, reduceOnly orders are supported for swap and future markets onlybrokerIdCCXTr1   )rS  r  r  ry  text)r   r  	stopPricetrailingAmountpegOffsetValuer   	ascendingabover   rQ  rK   belowbuy	StopLimitLimitIfTouchedStopMarketIfTouchedsellrz  TrailingStopPegpegPriceTypez9 createOrder() requires a triggerPrice parameter for the z order typer  ry  )r   r  r  r   r  Limitr  r  r  )r  rQ  
capitalizer%  r&   r1   r#  r   parse_to_intrR  safe_number_nr  check_required_argumentparse_to_numericr"   price_to_precisionr  privatePostOrderr  r  )r   rS  r  r  r  r  r+  rQ  	orderTyper  r  r  r  r   r  isTriggerOrderisTrailingAmountOrderr   triggerAboveisStopSellOrderisBuyIfTouchedOrderr  r,  s                          r  create_orderbitmex.create_orderz  sP    " !!!V$OOD)	__V\:
!6NVH-="477-^#^aghnao#o  s~  $~    ##DLL*fE 8 8 HITlOOD) 
 ))&2YZ++F4DFVW%T1 .d :2#//8JK-<^BRV]B]LTX%5,,]<LN`cjlsbtuw5=/;AQI4@ 0kI!5=*6<MI5A 1vI$#'6>"lf9L8kR[_jRj'+u}&IIZ<Z;~`im}`}#"&9%(>%9N,0,A,A.,Q()*;''+DGG6q,qt},}  AN  -N  O  O$($9$9$:Q:QRX:g$h!!*IYYv'tuF i;&>IQaDa#44T5L5LV5[\GG**69oN$!.GIYYv	?'CDF..t{{7/KLL&11s 	"p Ms"   LLK"L9L:LLc                 >  #    U R                  5       I S h  vN   0 nU R                  USS5      n	U	S Ln
U
(       Ga  U R                  US5      nUS:H  =(       d    US:H  nUS:X  d  US:X  a  U R                  SUSSS	/5        S nUS:X  a  US
:X  a  U(       a  SOSnO/U(       a  SOSnO#US:X  a  US
:X  a  U(       a  SOSnOU(       a  SOSnUS:H  =(       a    US:H  =(       d    US:H  nUS
:H  =(       a    US:H  =(       d    US:H  nU(       d  U(       a  SU	-   n	U R	                  U	5      US'   U R                  USS/5      nU R                  USS5      nUb5  UUS'   U R                  USS5      nUb  UUS'   U R                  U/ SQ5      nOXS'   Ub%  U R                  U R                  X%5      5      nUUS'   Ub  XhS'   U R                  U R                  SS5      nUUS'   U R                  U R                  X5      5      I S h  vN nU R                  U5      $  GN N7f)Nr  r  r   r  r  r   rQ  rK   r  r  r  r  r  r  r  rz  origClOrdIDr  r  )r  r  r  r  r  r  r  r  r  )r  r  r#  r  r  r  r  rR  r   privatePutOrderr  r  )r   r1   rS  r  r  r  r  r+  r  r  r  r   r  r  r  r  r  r  r  r  r,  s                        r  
edit_orderbitmex.edit_order  sP    !!!++F4DFVW .d : #//8JK-<^BRV]B]LTX%5,,]<LN`cjlsbtuIw5=/;AQI4@ 0kI!5=*6<MI5A 1vI#v~hY&5H4gi[fNfO#'5="{	EV8V7z\eiy\y"5!$~!5(,(=(=n(MG$%YYv(:<L'MNF((P"%0GM" ,,VYPM(%2	"YYv'RSF!#I##D$<$<V$LMC"%GJ$G##DLL*fE"--dkk'.JKK))W 	"T Ls"   HHG+HHHHc                   #    U R                  5       I Sh  vN   U R                  USS5      n0 nUc  XS'   OXES'   U R                  USS/5      nU R                  U R	                  XS5      5      I Sh  vN nU R                  US0 5      nU R                  US5      nUb0  UR                  S5      S:  a  [        U R                  S-   U-   5      eU R                  U5      $  N No7f)	aA  
cancels an open order

https://www.bitmex.com/api/explorer/#not /Order/Order_cancel

:param str id: order id
:param str symbol: not used by bitmex cancelOrder()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  r  r   errorr   z cancelOrder() failed: )r  safe_value_2r  privateDeleteOrderr  r%  r#  findr'   r1   r  )	r   r1   rS  r+  r  r  r,  r   r  s	            r  cancel_orderbitmex.cancel_order  s      !!!))&)_M !#I!.IYYv	?'CDF00W1MNN!R0  0zzHIQN#DGG.G$G%$OPP&& 	" Os#   C%C!AC%3C#4A.C%#C%idsc                   #    U R                  5       I Sh  vN   U R                  USS5      n0 nUc  XS'   OXES'   U R                  USS/5      nU R                  U R	                  XS5      5      I Sh  vN nU R                  U5      $  Nr N7f)aP  
cancel multiple orders

https://www.bitmex.com/api/explorer/#not /Order/Order_cancel

:param str[] ids: order ids
:param str symbol: not used by bitmex cancelOrders()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  r  )r  r  r  r  r  r  )r   r  rS  r+  r  r  r,  s          r  cancel_ordersbitmex.cancel_orders  s      !!!))&)_M !$I!.IYYv	?'CDF00W1MNN  ** 	" Os"   BB	AB3B4BBc                    #    U R                  5       I Sh  vN   0 nSnUb  U R                  U5      nUS   US'   U R                  U R                  X25      5      I Sh  vN nU R	                  XT5      $  N] N7f)a|  
cancel all open orders

https://www.bitmex.com/api/explorer/#not /Order/Order_cancelAll

:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not 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>`
Nr1   rS  )r  rQ  privateDeleteOrderAllr  r  )r   rS  r+  r  rQ  r,  s         r  cancel_all_ordersbitmex.cancel_all_orders(  s      !!![[(F &tGH33DKK4PQQP   22] 	" Rs"   A8A4AA8A6A86A8timeoutc                    #    U R                  5       I Sh  vN   SUS:  a  U R                  US-  5      OS0nU R                  U R                  X25      5      I Sh  vN nU$  NL N7f)a;  
dead man's switch, cancel all orders after the given timeout

https://www.bitmex.com/api/explorer/#not /Order/Order_cancelAllAfter

:param number timeout: time in milliseconds, 0 represents cancel the timer
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: the api result
Nr  r   rf  )r  r  privatePostOrderCancelAllAfterr  )r   r  r+  r  r,  s        r  cancel_all_orders_afterbitmex.cancel_all_orders_afterb  sl      !!!Wq[t((48q
 <<T[[=YZZ  	" [s"   A'A#AA'A%A'%A'c                    #    U R                  5       I Sh  vN   U R                  X5      I Sh  vN nU R                  X1S5      $  N/ N7f)aY  
fetch the set leverage for all contract markets

https://www.bitmex.com/api/explorer/#not /Position/Position_get

:param str[] [symbols]: a list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `leverage structures <https://docs.ccxt.com/#/?id=leverage-structure>`
NrS  )r  fetch_positionsparse_leverages)r   rW  r+  	leveragess       r  fetch_leveragesbitmex.fetch_leveragesy  sG      !!!..w??	##IAA 	"?   A
AA
AA
A
r  c                     U R                  US5      nUU R                  X25      U R                  US5      U R                  US5      U R                  US5      S.$ )NrS  r   r  )r  rS  r   longLeverageshortLeverage)r#  rP  r0  ri  )r   r  rQ  rZ  s       r  parse_leveragebitmex.parse_leverage  s_    ##Hh7&&x800<H --h
C!..xD
 	
r  c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  X15      nU R                  USUS5      $  NB N+7f)aD  
fetch all open positions

https://www.bitmex.com/api/explorer/#not /Position/Position_get

: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 structure <https://docs.ccxt.com/#/?id=position-structure>`
NrS  F)r  privateGetPositionparse_positionsfilter_by_array_positions)r   rW  r+  r,  resultss        r  r  bitmex.fetch_positions  s_      !!!0088D &&x9--gx%PPI 	"8s   AAAA*AAr   c                 v   U R                  U R                  US5      U5      nUS   nU R                  US5      nU R                  US5      nUSL a  SOSn[        R                  " U R                  USS5      5      nU R                  US	5      nU R                  XR                  US
5      5      n	U R                  XR                  US5      5      n
U R                  [        R                  " U R                  US5      5      5      nU R                  US5      nS nU R                  US5      nUb  US   S:X  a  SnOSnU R                  0 SU_SU R                  US5      _SU_SU R                  U5      _SU_SS _SS _SU_SU_SU_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 S _S!U R                  US"5      _U R                  US#5      U	U R                  US$5      U
U R                  US%5      US U R                  US&5      S S S'.
E5      $ )(NrS  r  crossMarginTcrossisolatedforeignNotionalhomeNotionalr~  maintMarginunrealisedPnl
currentQtyr  r   rz  shortlongr  r1   r  r  lastUpdateTimestampr   r  	contracts
entryPriceavgEntryPricerV  rC  notionalr  
collateralinitialMarginr}  initMarginReqmaintMarginReqliquidationPriceunrealisedPnlPcnt)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentageunrealizedPnlr  r   marginRatiorR  r   r   )r^  r#  r%  r+   r  r  rL  r'  r  safe_positionr  )r   r   rQ  rS  r  r  r   notionalStringsettleCurrencyCoder  r  r
  r  r  r  s                  r  parse_positionbitmex.parse_position	  s   @ !!$"2"28X"FO!##Hk:ooh>!,!4W:
 ++D,>,>xIZ\j,kl!--fh? 778JL\L\]egtLuv334FHXHXYacrHst%%g&8&89I9I(T`9a&bc	''?''.A#A#%!! #
H#
$""8Y7#
 f#
 1	#

 #
 "4#
 d#
 D#
 #
 L#
 $**8_E#
 ))(K@#
 #
 )).9#
 ((:>#
  $!#
" T--hE##
$ (,'7'7/'R!2+/+;+;HFV+W* $ 0 0;M N$**85HI!#7#
  	r  r   r)  c                   #    U R                  XE5      u  pEU R                  U5        U R                  5       I Sh  vN   U R                  U5      nU R	                  X5      nSnU R                  U5      u  pUS   UUU R                  XS   5      S.n	U R                  b  U R                  U R                  5      U	S'   U R                  U R                  X5      5      I Sh  vN n
U R                  X5      $  N N7f)a  
make a withdrawal

https://www.bitmex.com/api/explorer/#not /User/User_requestWithdrawal

:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr1   r  )r  r  r   r  otpToken)handle_withdraw_tag_and_paramscheck_addressr  r  rI  handle_network_code_and_paramsnetwork_code_to_idtwofatotp privatePostUserRequestWithdrawalr  r3  )r   r  r  r   r)  r+  r  r  networkCoder  r,  s              r  r   bitmex.withdraw	  s      99#F7#!!!==&++D9"AA&I ..{V<LM	
 ::!"&))DJJ"7GJ>>t{{7?[\\$ %%h99C 	" ]s"   8C:C6B%C: C8!C:8C:c                   #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN n/ n[        S[        U5      5       HW  nX5   nU R	                  US5      nU R                  U5      nU R                  USS5      n	U	(       d  MF  UR                  U5        MY     U R                  U5      nU R                  U5      n
U R                  U
SU5      $  N N7f)a  
fetch the funding rate for multiple markets

https://www.bitmex.com/api/explorer/#not /Instrument/Instrument_getActiveAndIndices

: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 `funding rate structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexed by market symbols
Nr   rS  rA   F)r  r=  r!  r"  r#  r^  r*  r  r<  parse_funding_ratesr  )r   rW  r+  r,  filteredResponser.  r  rZ  rQ  rA   r-  s              r  fetch_funding_ratesbitmex.fetch_funding_rates	  s      !!!AA&IIq#h-(A;D''h7H%%h/F>>&&%8Dt ''- ) %%g.))*:;##FHg>> 	"Is'   CCCCACACCc                    U R                  US5      nU R                  US5      nU R                  US5      n0 SU_SU R                  XB5      _SU R                  US5      _SS _SS _SU R                  US	5      _SU R                  U5      _S
U_SU R                  US5      _SU R                  U5      _SU_SU R                  US5      _SS _SS _SS _SS _SS _SS 0E$ )Nr  rS  fundingTimestampr  rV  
indexPriceinterestRateestimatedSettlePriceindicativeSettlePricer  fundingRatefundingDatetimenextFundingRateindicativeFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeintervalr#  rP  r  r  )r   r  rQ  r  rZ  r5  s         r  parse_funding_ratebitmex.parse_funding_rate	  sj   ##Hk:##Hh7**85GH
H
d&&x8
 ))(K@
 $	

 D
 #D$4$4X?V$W
 1
 
 4++HmD
  ?
 
 t//:QR
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                   #    U R                  5       I Sh  vN   0 nSnXR                  ;   a  U R                  U5      nUS   US'   OUb  UR                  S5      n[	        U5      n	/ SQn
U	S:  aA  U R                  US   U
5      (       a'  U R                  US   5      nUS   S-   US   -   nXS'   OU R                  U5      nUS   US'   Ub  U R                  U5      US'   Ub  X5S	'   U R                  US
5      nU R                  US
/5      nUb  U R                  U5      US'   Uc  Uc  SUS'   U R                  U R                  XT5      5      I Sh  vN nU R                  XX#5      $  GNT N7f)a  
Fetches the history of funding rates

https://www.bitmex.com/api/explorer/#not /Funding/Funding_get

:param str symbol: unified symbol of the market to fetch the funding rate history for
:param int [since]: timestamp in ms of the earliest funding rate to fetch
:param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms for ending date filter
:param bool [params.reverse]: if True, will sort results newest first
:param int [params.start]: starting point for results
:param str [params.columns]: array of column names to fetch in info, if omitted, will return all columns
:param str [params.filter]: generic table filter, send json key/value pairs, such as {"key": "value"}, you can key on individual fields, and do more advanced querying on timestamps, see the `timestamp docs <https://www.bitmex.com/app/restAPI#Timestamp-Filters>` for more details
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
Nr1   rS  rt  )nearestdailyweeklymonthly	quarterlybiquarterly	perpetualr   r   r  r  r  r  Trg  )r  
currenciesr  splitr"  rV  rQ  r  ri  r  publicGetFundingr  parse_funding_rate_histories)r   rS  r  r   r+  r  rQ  r  splitSymbolsplitSymbolLengthr   r  r,  s                r  fetch_funding_rate_history!bitmex.fetch_funding_rate_history	  s    " !!!__$==(D $T
GH ,,s+K #K 0kJ!A%4==Q+T+T}}[^4dc)KN:$*!V,$*4L!#'<<#6GK $G!!&'26G9-!%e!4GIM!%GI..t{{7/KLL 005PPO 	"6 Ms"   E/E*D<E/E-E/-E/c                     U R                  US5      nU R                  US5      nUU R                  X25      U R                  US5      U R                  U5      US.$ )NrS  r  r4  )r  rS  r4  r  r  r>  )r   r  rQ  rZ  r  s        r  parse_funding_rate_history!bitmex.parse_funding_rate_history0
  sb     ##D(3##D+6&&x8++D-@1 
 	
r  c                   #    Uc  [        U R                  S-   5      eUS:  d  US:  a  [        U R                  S-   5      eU R                  5       I Sh  vN   U R	                  U5      nUS   S:w  a!  US   S:w  a  [        U R                  S	-   5      eUS
   US.nU R                  U R                  XS5      5      I Sh  vN $  No N7f)aA  
set the level of leverage for a market

https://www.bitmex.com/api/explorer/#not /Position/Position_updateLeverage

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nz) setLeverage() requires a symbol argumentg{Gz?r:   z( leverage should be between 0.01 and 100r  rA   rB   z6 setLeverage() supports future and swap contracts onlyr1   )rS  r  )r"   r1   r#   r  rQ  r$   privatePostPositionLeverager  )r   r  rS  r+  rQ  r  s         r  set_leveragebitmex.set_leverageD
  s      >#DGG.Y$YZZtOCTWW'QQRR!!!V$&>V#v((BDGG&^^__Tl 
 55dkk'6RSSS 	" Ts%   AC	CA*C	 CC	C	r   c                   #    Uc  [        U R                  S-   5      eUR                  5       nUS:w  a  US:w  a  [        U R                  S-   5      eU R	                  5       I Sh  vN   U R                  U5      nUS   S:w  a!  US   S:w  a  [        U R                  S	-   5      eUS:X  a  S
OSnUS   US.nU R                  U R                  Xc5      5      I Sh  vN $  Ny N7f)aC  
set margin mode to 'cross' or 'isolated'

https://www.bitmex.com/api/explorer/#not /Position/Position_isolateMargin

:param str marginMode: 'cross' or 'isolated'
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nz+ setMarginMode() requires a symbol argumentr  r   z@ setMarginMode() marginMode argument should be isolated or crossr  rA   rB   z8 setMarginMode() supports swap and future contracts onlyFTr1   )rS  r  )	r"   r1   lowerr#   r  rQ  r$   privatePostPositionIsolater  )r   r   rS  r+  rQ  r  r  s          r  set_margin_modebitmex.set_margin_mode]
  s      >#DGG.[$[\\%%'
#
g(=TWW'iijj!!!V$6Nf$6&>X+EDGG&``aa&'1%Tl
 44T[[5QRRR 	" Ss%   A#C#%C&A4C#C!C#!C#c                   #    U R                  5       I Sh  vN   SnU R                  U5      u  p2Uc  [        U R                  S-   5      eU R	                  U5      nU R                  US5      nUS   U R                  X4S   5      S.nU R                  U R                  XR5      5      I Sh  vN nUUUUR                  SS5      R                  SS5      SS	.$  N N.7f)
a  
fetch the deposit address for a currency associated with self account

https://www.bitmex.com/api/explorer/#not /User/User_getDepositAddress

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: deposit chain, can view all chains via self.publicGetWalletAssets, default is eth, unless the currency has a default chain within self.options['networks']
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
Nz/ fetchDepositAddress requires params["network"]r  r1   r  )r  r  " )r  r  r  r   r)  )
r  r"  r"   r1   r  r  r#  privateGetUserDepositAddressr  replace)r   r  r+  r'  r  r  r,  s          r  fetch_deposit_addressbitmex.fetch_deposit_addressx
  s      !!!"AA&I#DGG._$_``==&69- ..{V<LM
 ::4;;w;WXX
 "''R088bA
 	
 	" Ys"   CCBC+C,-CCc                    U R                  US/ 5      n[        U5      nUS S S.S S S.0 S.nUS:w  a  U R                  US5      nU R                  U5      n[	        SU5       H  nX8   n	U R                  U	S5      n
U R                  US5      nU R                  X5      nU R                  U	S5      nU R                  [        R                  " X5      5      nS S S.US	S.S
.US   U'   US:X  d  M  XS   S'   S	US   S'   M     U$ )Nr   )r  rR  )r  r   r  r   r   r  r  r  r  F)r  r   r   r   r  rR  )	r%  r"  r#  r&  r!  r(  r'  r+   r)  )r   r  r  r   networksLengthr-  r  r  r.  r  r4  currencyCoder'  withdrawalFeeIdr  s                  r  parse_deposit_withdraw_fee!bitmex.parse_deposit_withdraw_fee
  s9   6 ??3
B7X"
 " 
 Q$$S'2E,,U3I1n-"+ ,,Wg>	#//&A"55iN"&"2"27O"L $ 1 1'2D2D_2` a'+4@(5U K3z";/ "Q&0=:&u-7<F:&|4 . r  codesc                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  X1S5      $  N/ N7f)aF  
fetch deposit and withdraw fees

https://www.bitmex.com/api/explorer/#not /Wallet/Wallet_getAssetsConfig

:param str[]|None codes: list of unified currency codes
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
Nr  )r  r   parse_deposit_withdraw_fees)r   rj  r+  assetss       r  fetch_deposit_withdraw_fees"bitmex.fetch_deposit_withdraw_fees
  sI      !!!11&99< //wGG? 	"9r  c                 n    U R                  S5      nU R                  USS5      nUS:w  a
  U(       a  U$ gU$ )NFr  r      )check_required_credentialsr%  )r   r   methodpathr+  configisAuthenticatedr  s           r  calculate_rate_limiter_cost"bitmex.calculate_rate_limiter_cost  s;    99%@vvq119r  c                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ U R                  U5      nSUS   0nUb  X'S'   Ub  X7S'   U R	                  S	Xt5      u  ptU R                  U R                  Xt5      5      I Sh  vN nU R                  XX#5      $  N Nz N7f)
a$  
retrieves the public liquidations of a trading pair

https://www.bitmex.com/api/explorer/#not /Liquidation/Liquidation_get

: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 bitmex api endpoint
:param int [params.until]: timestamp in ms of the latest liquidation
:param boolean [params.paginate]: 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 dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
NFrd   r  rS  r1   r  r  r  )r  r  r  rQ  handle_until_optionpublicGetLiquidationr  parse_liquidations)	r   rS  r  r   r+  r  rQ  r  r,  s	            r  fetch_liquidationsbitmex.fetch_liquidations  s      !!!88ATV`a::;NPV_dmmmV$fTl
 #(K $G229gN224;;w3OPP &&xFF5 	" n Qs4   CC8CC
A!C1C2C
CCc                     U R                  US5      nU R                  UU R                  X25      S U R                  US5      U R                  US5      U R	                  US5      S S S S S.
5      $ )NrS  r  r  r  )
r  rS  r
  r  r  r  	baseValue
quoteValuer  r  )r#  safe_liquidationrP  r  r0  )r   r   rQ  rZ  s       r  parse_liquidationbitmex.parse_liquidation5  s~     ##K:$$&&x8 ,,V^D%%k7;**;?&
  	r  reasonr   rs  headersbodyc
                 |   Uc  g US:X  a  [        U R                  S-   U-   5      eUS:  a  U R                  US0 5      n
U R                  U
S5      nU R                  S-   U-   nU R	                  U R
                  S   X5        U R                  U R
                  S   X5        US:X  a  [        U5      e[        U5      eg )Ni   i  r  messager   r   )	r(   r1   r%  r#  throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr#   r   )r   r  r  r   rs  r  r  r,  requestHeadersrequestBodyr  r  feedbacks                r  handle_errorsbitmex.handle_errorsM  s    3; 3!5663;OOHgr:E&&ui8Gww}t+H001I7]001I7]s{ **))r  c                 "    U R                  5       $ N)milliseconds)r   s    r  r  bitmex.nonce]  s      ""r  r   GETc                 J   SU R                   -   S-   U-   nUS:X  a  U(       a  USU R                  U5      -   -  nO@U R                  US5      nUb+  USU R                  SU05      -   -  nU R                  US5      nU R                  S   U   U-   n	U R                  S5      n
US:X  d  US	:X  a  U
(       a  U R                  5         X7-   nU R                  U R                  S
5      nSU R                  S.nU R                  U R                  5       U5      n[        U5      nX-  nXS
'   US:X  d  US:X  d  US:X  a  U(       a  U R                  U5      nX-  nU R                  U R                  U5      U R                  U R                  5      [         R"                  5      US'   XXeS.$ )Nz/api/rs  r  ?_formatr   Fr   r   r   zapplication/json)zContent-Typezapi-keyPOSTPUTDELETEzapi-signature)r   rs  r  r  )r6   	urlencoder#  r  r   rr  ri  r   r   rk  secondsstrr  hmacencodesecrethashlibsha256)r   rt  r   rs  r+  r  r  queryformatr   rv  authexpiresstringExpiress                 r  signbitmex.sign`  s   $,,&,t3U?t~~f555%%fi8F!t~~y&.ABBB695iis#e+99%@)xO++->D''mDG 2;;G hht||~w7GLM!D%2M"6U?f6H99V,DLD'+yyT1BDKKPTP[P[D\^e^l^l'mGO$dOOr   )rO  r  )___name__
__module____qualname____firstlineno__r   r   r   rA  rI  r   rL  rR  r[  r^  r   r   rc  dictr  r   r  r  r  r
   r   r  r  r   r  r  r  r  r  r   r   r  r  r   r  r  r3  r   r9  r   r   r?  r7  listr`  ro  r   r}  r  r  r  r  r   r   floatr   r  r  r  r  r  r  r   r  r   r  r   r  r  r   r   r,  r   r?  rO  rR  intrV  r[  r	   rb  rh  rn  rw  r}  r  r  r  r  __static_attributes____classcell__)r   s   @r  r-   r-      s   {# {z -/ ~: ~@.53 5 5G
.L *, y,V y,vw
4 w
F w
r;) ;)z *, =, =,~ @DB (S ( (S\ (T 8<B KC K K, 04$UYbd 'A 'AC 'As 'Aimnsit 'AR 59tZ^gi `c ` `TW `nrsxny `& 7;\`ik U U3 UVY Uptuzp{ U  37TX\eg [AC [As [ARU [Az
3]t ]x ]; ]~ .2SW`b 0Cs 0C# 0CS 0Cgklwgx 0Cd <@daenp MS M M[^ Muy  {F  vG M@:s :G
T G
X G
Q\ G
R 68 1 1F 1* 6:" G7 G G,4  6 >
 
4 
< ?CQUdhqs D D D3 D^a Dx|  ~B  yC DLl lv l l\: :"Hs HZ Zv Z Zx <@d[] >A >AS >A >Abfglbm >A@ mqy{ J2 J2I J2Y J2X] J2fi J2X fjx|  FH ,*3 ,* ,*9 ,*I ,*_b ,*ru ,*\ 9=R 'S '# '8 AER +tCy +# +0 59 83c 83t BD S . 8<B BW B9 B
t 
V 
x 
 8<B nQW nQ4PX> nQ`Nt NV N` QU]_ 0:3 0: 0: 0:# 0:do 0:d <@ ? ?| ?2
6 
[ 
4 >BPTcgpr 8Qs 8Q# 8Q]` 8Qt
v 
( ?C2 T3 T T2 DHPR S SS S6 =?  
  
>  
D: :x BFb )Hw )HV MO  BFTXac (Gs (G3 (Gc (GTV 0# s  c TX `c  # &eBSW P Pr  r-   )2 ccxt.async_support.base.exchanger   ccxt.abstract.bitmexr   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   typingr   ccxt.base.errorsr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   ccxt.base.decimal_to_precisionr*   ccxt.base.preciser+   r-   r  r  r  <module>r     sv    6 ,  P  P  P  P  P  P  P  * 0 - . ' & . ) * + 1 4 %c-PX{ c-Pr  