
    E#i                    x   S SK Jr  S SKJr  S SK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#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K4J5r5  S SK6J7r7   " S S\\5      r8g)    )Exchange)ImplicitAPIN)AccountAnyBalancesBorrowInterestBool
ConversionCrossBorrowRate
CurrenciesCurrencyDepositAddressFundingHistoryIntMarket
MarketTypeNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)DDoSProtection)ExchangeNotAvailable)	TICK_SIZE)Precisec                   H  ^  \ rS rSrS\4U 4S jjr0 4S\\   4S jjrS\	S\4S jr
0 4S\4S jjrS0 4S	\4S
 jjrS0 4S	\4S jjrSyS jr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0 4S\S\4S jjrSzS\	S\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0 4S\S\S\4S jjr 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#SzS\	S\S\!4S jjr$SSS0 4S\S \S\S\S\\%   4
S! jjr&SzS\S\%4S" jjr'0 4S# jr(0 4S\4S$ jjr)0 4S\S%\*S&\+4S' jjr,0 4S\S&\+S\4S( jjr-S0 4S\S)\.S%\*S*\+S+\/4
S, jjr0SS0 4S\S\S)\.S%\*S*\/S+\/4S- jjr1S0 4S\S\4S. jjr2S0 4S\4S/ jjr3SSS0 4S\S\S\S\\   4S0 jjr40 4S1\4S2 jjr5S\64S3 jr70 4S\64S4 jjr8SSS0 4S\S\S\S\\   4S5 jjr9SSS0 4S\S\S\S\\   4S6 jjr:S)\4S7 jr;SzS8\	S\S\4S9 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@0 4S;\S\A4S> jjrB0 4S;\S\A4S? jjrCSzS@\DS\A4SA jjrE0 4S\\F   4SB jjrGS0 4SC\HS\4SD jjrI0 4S;\S*\+SE\SF\S\J4
SG jjrKSzSH\	S@\DS\J4SI jjrLS0 4S;\S*\+SJ\SK\S\>4
SL jjrMSzSM\	S@\DS\>4SN jjrNSO\4SP jrOS0 4S\S;\4SQ jjrPSSS0 4S;\S\S\S\\>   4SR jjrQSSSS0 4S;\S\S\S\S\\R   4
SS jjrSSzST\	S\S\R4SU jjrT0 4S\S\U4SV jjrVS0 4S\S\W4SW jjrXSzS\S\U4SX jjrYSSS0 4S\S\S\S\\Z   4SY jjr[SzS\4SZ jjr\S{S\S\S\\Z   4S[ jjr]SSS0 4S;\S\S\S\\>   4S\ jjr^S0 4S]\S^\S*\/S\_4S_ jjr`S0 4S\S]\S^\S*\/S\_4
S` jjraSSS0 4S;\S\S\S\\_   4Sa jjrbSySb\	Sc\DSd\DS\_4Se jjrcSS0 4S\S\S\S\\d   4Sf jjreS0 4S\S\\d   4Sg jjrf0 4S\S\d4Sh jjrgSzSi\	S\S\d4Sj jjrh0 4S;\S\i4Sk jjrjSzS@\D4Sl jjrkS@\S\l4Sm jrmSn rnSoSp0 SS4Sq jroS;\HSr\Ss\St\Su\	Sv\4Sw jrpSxrqU =rr$ )|whitebit   returnc                    > U R                  [        [        U ]  5       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_S(S_S)S_E0 S*S_S+S_S,S_S-S_S.S_S/S0_S1S_S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_E0 S<S_S=S_S>S_S?S_S@S_SAS_SBS_SCS_SDS_SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS_ESSSSSSSSSSSSSSSM.ESNSOSPSQSRSSSTSUSVSWSXSYSZS[S\S].S^S_S`Sa.SbSc0SdSeSa.Sf.SgShSiSjSk.SlSm/0Sl/ SnQ0So/ SpQ0Sa.SbSl/ SqQ00Sl/ SrQ0So/ SsQ0Sa.St.SuSSU R	                  Sv5      U R	                  Sv5      Sw.0SxS/ SyQSzS0S{S{SS|SS}.S~S0SSS.SSSSS SSS SSSSS.SSSSSSSS.S SSS S SS.SSSSSSS.SSSSSS.SSS S SSSS.SSS S S SSSS.SS0SSS S SS.S.
SS0SS0SS0S.S S S.S.[
        [        [        [        [        [        [        [        [        [        [        [        [        [        [        S.[        [        [        [        [        [        [        S.S.S.5      $ )Nr3   WhiteBitv4EE2   TCORSspotmarginswapfutureFoptioncancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscreateConvertTradecreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreatePostOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTriggerOrder	editOrderfetchAccountsfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingLimitsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPremiumIndexOHLCVfetchStatusfetchTicker)fetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeesfetchTransactionsfetchWithdrawalsrepayCrossMarginrepayIsolatedMarginsetLeveragetransferwithdraw1m3m5m15m30m1h2h4h6h8h12h1d3d1w1M)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zchttps://user-images.githubusercontent.com/1294454/66732963-8eb7dd00-ee66-11e9-849b-10d9282bb9e0.jpgz"https://whitebit.com/api/v1/publiczhttps://whitebit.com/api/v1)publicprivater   z"https://whitebit.com/api/v2/publicz"https://whitebit.com/api/v4/publiczhttps://whitebit.com/api/v4)v1v2r8   zhttps://www.whitebit.comz-https://github.com/whitebit-exchange/api-docsz!https://whitebit.com/fee-schedulezBhttps://whitebit.com/referral/d9bdf40e-28f2-4b52-b2f9-cd1415d82963)logoapiwwwdocfeesreferralgetzv1/healthcheck)marketstickerstickersymbolszdepth/resulthistoryklinepost)zaccount/balance	order/neworder/cancelorderszaccount/order_historyzaccount/executed_historyzaccount/executed_history/allzaccount/order)r   r   assetsfeezdepth/{market}trades/{market})r   zcollateral/marketsr   zorderbook/depth/{market}zorderbook/{market}r   r   timepingr   futureszplatform/statuszmining-pool)Kzcollateral-account/balancez"collateral-account/balance-summaryz$collateral-account/positions/historyzcollateral-account/leveragez!collateral-account/positions/openzcollateral-account/summaryz"collateral-account/funding-historyzmain-account/addresszmain-account/balancezmain-account/create-new-addresszmain-account/codeszmain-account/codes/applyzmain-account/codes/myzmain-account/codes/historyzmain-account/fiat-deposit-urlzmain-account/historyzmain-account/withdrawzmain-account/withdraw-payzmain-account/transferzmain-account/smart/planszmain-account/smart/investmentz#main-account/smart/investment/closezmain-account/smart/investmentszmain-account/feez+main-account/smart/interest-payment-historyztrade-account/balanceztrade-account/executed-historyztrade-account/order/historyztrade-account/orderzorder/collateral/limitzorder/collateral/marketzorder/collateral/stop-limitzorder/collateral/trigger-marketzorder/collateral/bulkr   zorder/marketzorder/stock_marketzorder/stop_limitzorder/stop_marketr   zorder/cancel/allzorder/kill-switchzorder/kill-switch/statusz
order/bulkzorder/modifyzorder/conditional-cancelr   z
oco-orderszorder/collateral/ocozorder/oco-cancelzorder/oto-cancelzprofile/websocket_tokenzconvert/estimatezconvert/confirmzconvert/historyzsub-account/createzsub-account/deletezsub-account/editzsub-account/listzsub-account/transferzsub-account/blockzsub-account/unblockzsub-account/balanceszsub-account/transfer/historyzsub-account/api-key/createzsub-account/api-key/editzsub-account/api-key/deletezsub-account/api-key/listzsub-account/api-key/resetz#sub-account/api-key/ip-address/listz%sub-account/api-key/ip-address/createz%sub-account/api-key/ip-address/deletezmining/rewardsz
market/feezconditional-orders)webr   r   r8   tradingz0.001)	tierBased
percentagetakermakerr   )EURUSDRUBUAHaccountmain
collateral)fundingr   r<   r=   tradeBEP20BSCccxt)timeDifferenceadjustForTimeDifferencefiatCurrenciesrR   accountsByTypenetworksByIddefaultTypebrokerId)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergd   )r   limitdaysBack	untilDayssymbolRequired)checkActivecheckExecutedr   r   triggerr   )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   r     )
sandboxrJ   createOrdersrq   ru   rt   rw   rU   rr   r   extendsdefault)linearinverse)r   r<   r>   r?   )zUnauthorized request.zThe market format is invalid.zMarket is not availablezInvalid payload.zAmount must be greater than 0zNot enough balance.zThe order id field is required.zNot enough balancezThis action is unauthorized.z6This API Key is not authorized to perform self action.zUnexecuted order was not found.zThe selected from is invalid.503422)zThis action is unauthorizedz$Given amount is less than min amountzMin amount stepzTotal is less thanzfee must be no less thanzEnable your key in API settingsz'You don't have such amount for transfer)exactbroad)idnameversion	countries	rateLimitprohas
timeframesurlsr   r   optionsfeaturesprecisionMode
exceptions)deep_extendsuperr3   describeparse_numberr0   r%   r)   r(   r+   r*   r&   r,   r/   )self	__class__s    G/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/whitebit.pyr  whitebit.describe   s*   h > @SSS $S 	S
 %S %S "4S 'S tS S %dS 'S /S ,US 0S  t!S" &t#S$ '%S& ('S( "4)S* %d+S, T-S.  /S0 1S2 +E3S4 )%5S6 $T7S8 $T9S: $U;S< +D=S> '?S@ (ASB "4CSD ESF &tGSH (ISJ 1%KSL  MSN +DOSP *:QSR +DSST &tUSV %dWSX #DYSZ *5[S\ $T]S^ "5_S` *5aSb +EcSd ueSf "5gSh iSj !%kSl  mSn doSp +EqSr "4sSt duSv !$wSx tySz #D{S|  }S~ 'S@ $UASB !$CSD )%ESF tGSH tISJ !%!##($(&*(,%)$($)',#  eSj $ ~ #G#@
 !"F #G#@ 2F;`%, (   
  	! 4   	   $  L!N %aWM^ !&"&!..w7!..w7	 #$+0">v!  &""*## U!  &"%,  %&*(,,1,0).+06:#'#("&#(	( #($)$)+/27/4#()$, %)&+!$$(%)*/& (,)-*/&+#($)# ',!$#($)*/( ',!$$(%)#($)*/$ ',!$$(,0%)#($)*/	*  # ',!$$(%)*/)KL\ y
 "9 "9 	 ##s]| ' .A5>/8(25A+<7C*;4DN^7D5?/(" 4D<H'3*60<7G@Q#SdC
 d d	    c                     U R                   S   (       a  U R                  5         U R                  5       nU R                  U5      $ )z
retrieves data on all markets for whitebit

https://docs.whitebit.com/public/http-v4/#market-info

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r   )r  load_time_differencev4PublicGetMarketsparse_markets)r	  paramsr   s      r  fetch_marketswhitebit.fetch_markets  s>     <<12%%'))+0 !!'**r  marketc                    U R                  US5      nU R                  US5      nU R                  US5      nUS:X  a  SOUnU R                  U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US	-   U-   nU	S
:H  nU=(       a    U(       + nSnU R                  U R	                  U R                  US5      5      5      nUnS nS nU(       a$  UnU R                  U5      n
US-   U
-   nSnSnSnSnOSnU R                  US5      n[
        R                  " US5      nU R                  US5      n[
        R                  " US5      n0 SU_SU_SU_SU_SU
_SU_SU_SU_SU_SU(       + _SU_SU_SS_SS_SU_S U_S!U_UU R                  U5      U R                  U5      US S S S UU R                  U R	                  U R                  US"5      5      5      S#.S S S$.U R                  US%5      S S$.S S S$.U R                  US&5      U R                  US'5      S$.S(.S US).E$ )*Nr   stockmoneyPERPUSDTtradesEnabledisCollateraltype/r   F	stockPrec:r>   Tr<   takerFee100makerFeer   symbolbasequotesettlebaseIdquoteIdsettleIdr=   r?   r@   activecontractr   	moneyPrec)amountpriceminmax	minAmountminTotalmaxTotal)r   r.  r/  cost)r   r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)safe_stringsafe_currency_code
safe_valuer  parse_precisionr1   
string_divsafe_number)r	  r  r   r(  r)  r%  r&  r+  r  typeIdr'  r*  r$  r>   r=   r,  amountPrecisionr7  r   r   r  takerFeeRater   makerFeeRater   s                            r  parse_marketwhitebit.parse_market  s-   ff-!!&'2""673$.&W&&v.''09v~>!!&&1e#"*d(++D,@,@AQAQRXZeAf,gh&H,,X6Fc\F*FDHFGD''
;""<7''
;""<72
"2
f2
 D2
 U	2

 f2
 f2
 w2
 2
 D2
 H2
 f2
 D2
 e2
 e2
 f2
  !2
" f#2
$ &&u-&&u-(")**4+?+?@P@PQWYd@e+fg  
  ++FK@
  
  ++FJ?++FJ?$ c2
 2	
r  c                    U R                  U5      n[        UR                  5       5      n0 n[        S[	        U5      5       GH  nX5   nX&   nU R                  U5      nSU;   n	0 n
U R                  US0 5      nU R                  US/ 5      nU R                  US/ 5      nU R                  US0 5      nU R                  US0 5      nU R                  US0 5      nU R                  X5      n[        S[	        U5      5       H  nUU   nU R                  U5      nUUS	U R                  UU5      U R                  UU5      S	S	U R                  US
S	5      U R                  USS	5      S.U R                  US
S	5      U R                  USS	5      S.S.S.U
U'   M     U R                  UUUS	S	U R                  US5      U R                  US5      S	S	U	(       a  SOSU R                  U R                  U R!                  US5      5      5      S	S	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.5      XH'   GM     U$ )z
fetches all available currencies on an exchange

https://docs.whitebit.com/public/http-v4/#asset-status-list

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
r   	providersnetworksdeposits	withdrawsr=  depositr   Nr1  r2  r0  rQ  r   )r   networkr+  rQ  r   r   r<  r=  can_depositcan_withdrawfiatcryptocurrency_precisionmin_withdrawmax_withdrawmin_depositmax_deposit)r.  r   rQ  )r   coder?  r   r+  rQ  r   r   rN  r  r<  r=  )v4PublicGetAssetslistkeysrangelenrA  	safe_dict	safe_listarray_concatnetwork_id_to_codein_arrayrE  safe_currency_structure	safe_boolr  rC  r@  )r	  r  responseidsresultir   currencyr]  hasProviderrN  rawNetworksdepositsNetworkswithdrawsNetworksnetworkLimitsdepositLimitswithdrawLimitsallNetworksj	networkIdnetworkCodes                        r  fetch_currencieswhitebit.fetch_currenciesA  s    ))&1D 8==?#q#c(#AB|H**2.D&(2KH..:rBK#~~k:rJ ${K L NN8XrBM NN=)RHM!^^M:rJN++,<PK1c+./'N	"55i@#*"#}}Y8HI $i9J K!% $(#3#3M5$#O#'#3#3M5$#O$
 $(#3#3NE4#P#'#3#3NE4#P%	)% 0,  77 >>(MB NN8^D "-8!..t/C/CDDTDTU]_sDt/uv  $#
  $//.I#//.I!
  $//-H#//-H 9 FLI $~ r  Ncodesc                    U R                  5         U R                  U5      n[        UR                  5       5      n0 n0 n[	        S[        U5      5       Hj  nXG   nX8   n	U R                  U5      n
U R                  U	S0 5      nU R                  US5      XZ'   U R                  U	S0 5      nU R                  US5      Xj'   Ml     UUUS.$ )ar  
@deprecated
       please use fetchDepositWithdrawFees instead

       https://docs.whitebit.com/public/http-v4/#fee

       :param str[]|None codes: not used by fetchTransactionFees()
       :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>`
       r   r   fixedrQ  )r   rQ  r?  )	load_marketsv4PublicGetFeer_  r`  ra  rb  rA  rB  r@  )r	  r|  r  rj  currenciesIdswithdrawFeesdepositFeesrm  rn  datar]  r   rQ  s                r  fetch_transaction_feeswhitebit.fetch_transaction_fees  s     	&&v.4 X]]_-q#m,-A$'H%D**84DtZ<H!%!1!1(G!DLoodIr:G $ 0 0' BK . %"
 	
r  c                 f    U R                  5         U R                  U5      nU R                  X15      $ )a4  
fetch deposit and withdraw fees

https://docs.whitebit.com/public/http-v4/#fee

:param str[]|None codes: not used by fetchDepositWithdrawFees()
: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>`
)r  r  parse_deposit_withdraw_fees)r	  r|  r  rj  s       r  fetch_deposit_withdraw_fees$whitebit.fetch_deposit_withdraw_fees  s4     	&&v.V //@@r  c                    0 nU R                  U5      n[        UR                  5       5      n[        S[	        U5      5       GH2  nXV   nUR                  S5      nUS   n	X   n
U R                  U	5      nUb  U R                  X5      (       d  MN  U R                  XK5      nUc  U R                  0 5      XK'   XU   S   U'   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Ub  SOS S	.nUUb  SOS S	.nUb4  [	        U5      nUSUS-
   nU R                  U5      nUUS
.XK   S   U'   GM$  UXK   S'   UXK   S'   GM5     [        UR                  5       5      n[        S[	        U5      5       H/  nUU   nU R                  U5      nU R                  XK   U5      XK'   M1     U$ )Nr    r?     r   rQ  r~  F)r   r   )r   rQ  rN  )market_codesr_  r`  ra  rb  splitrA  rg  rB  deposit_withdraw_feer@  rE  rf  rn  $assign_default_deposit_withdraw_fees)r	  rj  r|  currencyIdKeydepositWithdrawFeescurrencyIdsrm  entry
splitEntry
currencyIdfeeInfor]  depositWithdrawFeerx  r   rQ  withdrawFee
depositFeewithdrawResultdepositResultnetworkLengthry  depositWithdrawCodesrn  s                           r  r  $whitebit.parse_deposit_withdraw_fees>  s   V %'!!%(8==?+q#k*+ANES)J#AJoG**:6D4==#=#=%)__5H%O"%-040I0I"0M'-;BD)&1%8 ,,Z;	??7J?//'9="..xA!--gw?
&,7,C%$(
 &,6,B%' ($'	NM )!MA,= >I"&"9"9)"DK$2#0J'-j9+F
 =K'-j9;H'-i8E ,F  $$7$<$<$>?q#234A'*D}}T*H(,(Q(QReRkmu(v% 5 #"r  c           	         U R                  5         U R                  U5      n0 n[        S[        U R                  5      5       H  nU R                  U   nU R                  U5      nU R                  X&S   0 5      nU R                  US5      nU R                  US5      n	[        R                  " US5      n[        R                  " U	S5      n	UUS   SSU R                  U5      U R                  U	5      S	.X5'   M     U$ )
a.  
fetch the trading fees for multiple markets

https://docs.whitebit.com/public/http-v4/#asset-status-list

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
r   r(  	maker_fee	taker_feer"  r$  TF)r?  r$  r   r   r   r   )r  r^  ra  rb  r   r  rB  r@  r1   rD  r  )
r	  r  rj  rl  rm  r$  r  r   r#  r!  s
             r  fetch_trading_feeswhitebit.fetch_trading_fees  s     	))&1$ q#dll+,A\\!_F[[(F//(8,<bAC''[9H''[9H))(E:H))(E:H *""**84**84FN -  r  r   c           	      z   U R                  5         0 n[        U R                  R                  5       5      n[	        S[        U5      5       GH  nXE   nU R                  U   nU(       a
  US   (       d  M*  US   nU(       a3  Sn	[	        S[        U5      5       H  n
X   U:X  d  M  Sn	  O   U	(       d  Mi  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=(       a/    U R                  US	5      S
L=(       a    U R                  US5      S
LnU=(       a/    U R                  US	5      S
L=(       a    U R                  US5      S
LnU=(       a/    U R                  US	5      S
L=(       a    U R                  US5      S
LnU(       d  GMc  U(       d  GMm  U(       d  GMw  U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.X8'   GM     U$ )a@  
fetch the trading limits for a market

https://docs.whitebit.com/public/http-v4/#market-info

:param str[]|None symbols: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `trading limits structure <https://docs.ccxt.com/#/?id=trading-limits-structure>`
r   r$  FTr=  r.  r/  r6  r1  Nr2  r0  )r.  r/  r6  r?  r=  )r  r_  r   r`  ra  rb  rc  rE  )r	  r   r  rl  	marketIdsrm  marketIdr  r$  symbolFoundrw  r=  amountLimitspriceLimits
costLimitshasAmountLimitshasPriceLimitshasCostLimitss                     r  fetch_trading_limitswhitebit.fetch_trading_limits  sp    	Z **,-	q#i.)A |H\\(+F!1H%F#q#g,/AzV+&* 0 #^^FH5F>>&(;L..9K7J*  Wt/?/?e/T\`/`  Weieueu  wC  EJ  fK  SW  fWO(  ST-=-=k5-QY]-]  Sbfbrbrs~  AF  cG  OS  cSN&  O4+;+;J+NVZ+Z  O_c_o_opz  }B  `C  KO  `OM>>mm" $(#3#3L%#H#'#3#3L%#H#
 $(#3#3K#G#'#3#3K#G"
 $(#3#3J#F#'#3#3J#F!"3 *T r  c                 p   U R                  5         [        R                  " U R                  5       U R	                  U5      /6 u  p40 n[        UR                  5       5      n[        S[        U5      5       GH  nXg   nX8   n	U	(       d  M  Ub  U R                  X5      (       d  M0  Sn
[        UR                  5       5      n[        S[        U5      5       H!  nX   nXM   nU(       d  M  US   U:X  d  M  Un
  O   U	S   S   S   U	S   S   S   S.U	S   S	   S   U	S   S	   S   S.S
.nU
(       a  U
S   nU
S	   nU(       ah  SU R                  US5      0nUS   (       aB  U R                  US   S5      U R                  US   S5      U R                  US   S5      S.US'   UUS   S'   U(       ah  SU R                  US5      0nUS   (       aB  U R                  US   S5      U R                  US   S5      U R                  US   S5      S.US'   UUS	   S'   U	S   (       a  U	S   US'   U	US.XX'   GM     U$ )a  
fetch the deposit and withdrawal limits for a currency

https://docs.whitebit.com/public/http-v4/#asset-status-list
https://docs.whitebit.com/public/http-v4/#fee

:param str[]|None codes: unified currency codes
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding limits structure <https://docs.ccxt.com/#/?id=funding-limits-structure>`
r   Nr   r=  rQ  r1  r2  r0  r   rR  r~  flexmin_feemax_feepercent)r1  r2  r  r   rN  r  )r  asynciogatherrz  r  r_  r`  ra  rb  rg  rE  )r	  r|  r  currenciesDatafeesDatarl  currencyKeysrm  r]  rn  feeDatafeeKeysrw  feeKeyr   r=  r  r  depositFeeDatawithdrawFeeDatas                       r  fetch_funding_limitswhitebit.fetch_funding_limits+  s    	#*>>!!#'4
 $ x N//12q#l+,A?D%+H t)C)CG8==?+G1c'l+ &33x=D0!G , $H-i8?#H-i8?
 $H-j9%@#H-j9%@	F $Y/
%j1!1!1*g!F&N "&)#'#3#3Jv4F	#R#'#3#3Jv4F	#R'+'7'7
68JI'V2v.
 0>F9%e,!1!1+w!G'O #6*#'#3#3K4G#S#'#3#3K4G#S'+'7'7F8KY'W3/
 1@F:&u-
#%-j%9z"  FLu -| r  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                  Xc5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.whitebit.com/public/http-v4/#market-activity

: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>`
r  r   rl  )r  r  v1PublicGetTickerextendrc  parse_ticker)r	  r$  r  r  requestrj  r   s          r  fetch_tickerwhitebit.fetch_ticker  sn     	V$fTl
 ))$++g*FG$ (B7  00r  r   c           	      >   U R                  US5      nU R                  X25      nU R                  U/ SQ5      nU R                  USU5      nU R                  0 SUS   _SS _SS _SU R                  US5      _SU R                  US5      _S	U R	                  US	S
5      _SS _SU R	                  USS5      _SS _SS _SU R                  US5      _SU_SU_SS _SS _SU R                  US5      _SS _U R                  U/ SQ5      U R                  U/ SQ5      US.EU5      $ )NtradingPairs)last
last_price	lastPricecloser$  	timestampdatetimehighlowbid
highestBid	bidVolumeask	lowestAsk	askVolumevwapopenr  previousClosechanger   average)base_volumevolumebaseVolume24h)quote_volumedealquoteVolume24h)
baseVolumequoteVolumer?  )r@  safe_marketsafe_string_nsafe_tickersafe_string_2)r	  r   r  r  r  r  s         r  r  whitebit.parse_ticker  s   h ##FN;!!(3!!&*MN  $7 !
fX&!
!
 !
 D$$VV4	!

 4##FE2!
 4%%fe\B!
 !
 4%%fe[A!
 !
 D!
 D$$VV4!
 U!
 D!
 T!
 d!
  $**68<!!
" t#!
$ ,,V5_`--f6`a)!
* + 	r  r   c                 Z   U R                  5         U R                  USS5      nU R                  USS5      nSU0nSnUb  U R                  U5      nUS   US'   U(       a   U R                  U R	                  Xc5      5      n[        S[        U5      5       HV  n	X   n
U R                  U
S5      nX:X  d  M   U R                  U
S5      nU R                  USS	5      nU R                  X5      s  $    U(       a   U R                  U R	                  Xc5      5      n[        UR                  5       5      n[        S[        U5      5       Hk  n	X   nU R                  USS	5      nX   n[        S[        U5      5       H4  nUU   n
U R                  U
S5      nX:X  d  M!  U R                  X5      s  s  $    Mm     [        U R                   S
-   U-   5      e! [         a"  n[        U[        5      (       d  Ue SnAGNSnAff = f! [         a!  n[        U[        5      (       d  Ue SnANpSnAff = f)aj  
fetches information on an order by the id

https://docs.whitebit.com/private/http-trade-v4/#query-unexecutedactive-orders
https://docs.whitebit.com/private/http-trade-v4/#query-executed-orders

: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 boolean [params.checkActive]: whether to check active orders(default: True)
:param boolean [params.checkExecuted]: whether to check executed orders(default: True)
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   Tr   orderIdNr   r  r   _z fetchOrder() order not found: )r  ri  r  v4PrivatePostOrdersr  ra  rb  r@  r  parse_order	Exception
isinstancer,   %v4PrivatePostTradeAccountOrderHistoryr_  r`  r   )r	  r   r$  r  r   r   r  r  rj  rm  orderr  r  	marketNewerrorr  r   rw  s                     r  fetch_orderwhitebit.fetch_order+  s    	nnV]DAvEr
 [[(F &tGH 33DKK4PQq#h-0A$KE"..ui@G}#'#3#3E8#D$($4$4XtS$I	#//AA 1  EEdkkRYFbc 1	q#i.1A(|H $ 0 04 EI%/F"1c&k2 &q	"&"2"25$"?"=#'#3#3E#EE	 3	 2 DGG&GG"LMM-   "5-88K 9 $   "5-88K 9 sJ   !AG 67G .G 8BG? G? /G? 
G<G77G<?
H*	H%%H*c                    U R                  5         U R                  U5      nSnU R                  USSU5      u  p2SnUS:X  a  U R                  U5      nOU R	                  U5      nU R                  US5      nUb  U R                  XQ5      $ [        UR                  5       5      n0 n[        S[        U5      5       H5  nXh   n	U R                  U	5      n
U R                  XI   U
5      nUS   nXU'   M7     U R                  USU5      $ )aI  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://docs.whitebit.com/public/http-v4/#market-activity

:param str[] [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
:param str [params.method]: either v2PublicGetTicker or v4PublicGetTicker default is v4PublicGetTicker
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
v4PublicGetTickerr   methodNrl  r   r$  )r  market_symbolshandle_option_and_paramsr  v2PublicGetTickerrd  parse_tickersr_  r`  ra  rb  r  r  filter_by_array_tickers)r	  r   r  r  rj  
resultListr  rl  rm  r  r  r   r$  s                r  fetch_tickerswhitebit.fetch_tickersh  s    	%%g.$66v~xY_`((--f5H--f5H ^^Hh7
!%%j::)	q#i.)A |H%%h/F&&x'96BFH%F#6N * ++FHgFFr  r   c                     U R                  5         U R                  U5      nSUS   0nUb  X%S'   U R                  U R                  XS5      5      nU R	                  US5      nU R                  XaU5      $ )a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.whitebit.com/public/http-v4/#orderbook

: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   r   r  )r  r  v4PublicGetOrderbookMarketr  safe_timestampparse_order_book)r	  r$  r   r  r  r  rj  r  s           r  fetch_order_bookwhitebit.fetch_order_book  s~     	V$fTl
 $G224;;w3OP( ''+>	$$XyAAr  sincec                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  Xd5      5      nU R	                  XuX#5      $ )a  
get the list of most recent trades for a particular symbol

https://docs.whitebit.com/public/http-v4/#recent-trades

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r  r   )r  r  v4PublicGetTradesMarketr  parse_tradesr	  r$  r  r   r  r  r  rj  s           r  fetch_tradeswhitebit.fetch_trades  s^     	V$fTl
 //G0LM   5@@r  c                 B   U R                  5         Sn0 nUb  U R                  U5      nUS   US'   U R                  U R                  Xd5      5      n[	        U[
        5      (       a  U R                  XuX#5      $ / n[        UR                  5       5      n	[        S[        U	5      5       HO  n
X   nU R                  USS5      nU R                  X{/ 5      nU R                  XX#5      nU R                  X5      nMQ     U R                  USS5      nU R                  XUS5      $ )a  
fetch all trades made by the user

https://docs.whitebit.com/private/http-trade-v4/#query-executed-order-history

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nr   r  r   r  r  )r  r  (v4PrivatePostTradeAccountExecutedHistoryr  r  r_  r  r`  ra  rb  r  rB  re  	sort_by_2filter_by_since_limit)r	  r$  r  r   r  r  r  rj  resultsr`  rm  r  r  	rawTradesparseds                  r  fetch_my_tradeswhitebit.fetch_my_trades  s    	[[(F &tGH@@WA]^L h%%$$XuDDG(D1c$i(7 ,,XtSA	 OOHC	**9N++G< ) nnWk4@G--ge[QQr  r   c                 L   U R                  S U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5      nU R                  USS5      nU R                  US	S
5      nU R                  USS5      n	US   n
U R	                  US5      nS nUb
  US:X  a  SOSnS nU R                  US5      nUb$  UU R                  U R                  US5      5      S.nU R                  UUU R                  U5      U
UUS UU	UUUUS.U5      $ )Nr   trade_timestampdealOrderIdr  r  r/  r.  r  r   tradeIDr  sider$  roler  r   r   r   feeAssetr6  rn  )r?  r  r  r$  r   r  r  takerOrMakerr  r/  r.  r6  r   )r  safe_timestamp_2r  r@  safe_integerrA  
safe_tradeiso8601)r	  r   r  r  r  r6  r/  r.  r   r  r$  r   r#  r   feeCosts                  r  parse_tradewhitebit.parse_trade#  sc   X !!$/))%9JK	$$UM9Ev.  0##E8^DtY7!!%8!  / '+qy7wL""5%0 33D4D4DUJ4WXC "Y/( 
  	r  r   	timeframec                    U R                  5         U R                  U5      nUS   U R                  U R                  X"5      S.nUb*  SnUc  Un[	        XH5      nU R                  US-  5      n	XS'   Ub  [	        US5      US'   U R                  U R                  Xu5      5      n
U R                  U
S/ 5      nU R                  XX#U5      $ )aC  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.whitebit.com/public/http-v1/#kline

: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
:returns int[][]: A list of candles ordered, open, high, low, close, volume
r   )r  intervalr     startr   rl  )
r  r  r@  r   r1  parse_to_intv1PublicGetKliner  rd  parse_ohlcvs)r	  r$  r+  r  r   r  r  r  maxLimitr/  rj  rl  s               r  fetch_ohlcvwhitebit.fetch_ohlcvs  s     	V$Tl(()O
 H} (E%%edl3E$G"5$/GG((W)EF (B7  5IIr  c           	          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      /$ )Nr   r              )r  rE  )r	  ohlcvr  s      r  parse_ohlcvwhitebit.parse_ohlcv  sn     q)UA&UA&UA&UA&UA&
 	
r  c                 h    U R                  U5      nU R                  US5      nUS:X  a  SOUSSSUS.$ )a)  
the latest known information on the availability of the exchange API

https://docs.whitebit.com/public/http-v4/#server-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   pongokN)statusupdatedetaurlr?  )v4PublicGetPingr@  )r	  r  rj  rA  s       r  fetch_statuswhitebit.fetch_status  sJ     ''/ !!(A.%/df
 	
r  c                 H    U R                  U5      nU R                  US5      $ )a*  
fetches the current integer timestamp in milliseconds from the exchange server

https://docs.whitebit.com/public/http-v4/#server-time

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
r   )v4PublicGetTimer%  )r	  r  rj  s      r  
fetch_timewhitebit.fetch_time  s)     ''/   622r  r  r6  c                 T    SU0nU R                  USUSSU R                  XT5      5      $ )a  
create a market order by providing the symbol, side and cost
:param str symbol: unified symbol of the market to create an order in
:param str side: 'buy' or 'sell'
: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>`
r6  r  r   N)create_orderr  )r	  r$  r  r6  r  reqs         r  create_market_order_with_cost&whitebit.create_market_order_with_cost  s6     D
   4D$++cBZ[[r  c                 (    U R                  USX#5      $ )an  
create a market buy order by providing the symbol and cost
: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>`
buy)rO  )r	  r$  r6  r  s       r  !create_market_buy_order_with_cost*whitebit.create_market_buy_order_with_cost  s     11&%NNr  r  r.  r/  c                 F   U R                  5         U R                  U5      nUS   US.nSn	U R                  US5      u  pU	b9  US:w  d  US:w  a  [        U R                  S-   5      eU R                  X5      US'   OU R                  X5      US'   U R                  US	S
5      n
U
c5  U R                  U R                  S5      nUb  XR                  5       -   US
'   OXS
'   U R                  US
/5      nU R                  US5      nUS:H  nUS:H  nU R                  U/ SQ5      nUSLnU R                  USU5      nU R                  SU5      u  nnU(       a  SUS'   Ub  US:w  a  [        U R                  S-   5      eU R                  U/ SQ5      nUSL=(       d    US:H  nSnU(       a  U R!                  X5      US'   U(       a6  U R!                  X5      US'   U R#                  U R%                  X5      5      nGOU(       a!  U R'                  U R%                  X5      5      nOU R)                  U R%                  X5      5      nOU(       a]  U R!                  X5      US'   U(       a!  U R+                  U R%                  X5      5      nOU R-                  U R%                  X5      5      nOlU(       a!  U R/                  U R%                  X5      5      nODU	b!  U R1                  U R%                  X5      5      nO U R3                  U R%                  X5      5      nU R5                  U5      $ )a  
create a trade order

https://docs.whitebit.com/private/http-trade-v4/#create-limit-order
https://docs.whitebit.com/private/http-trade-v4/#create-market-order
https://docs.whitebit.com/private/http-trade-v4/#create-buy-stock-market-order
https://docs.whitebit.com/private/http-trade-v4/#create-stop-limit-order
https://docs.whitebit.com/private/http-trade-v4/#create-stop-market-order

:param str symbol: unified symbol of the market to create an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much of currency you want to trade in units of base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param float [params.cost]: *market orders only* the cost of the order in units of the base currency
:param float [params.triggerPrice]: The price at which a trigger order is triggered at
:param bool [params.postOnly]: If True, the order will only be posted to the order book and not executed immediately
:param str [params.clientOrderId]: a unique id for the order
:param str [params.marginMode]: 'cross' or 'isolated', for margin trading, uses self.options.defaultMarginMode if not passed, defaults to None/None/None
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   )r  r  Nr6  rR  r  z; createOrder() cost is only supported for market buy ordersr.  clOrdIdclientOrderIdr   r  r   )r   	stopPriceactivation_priceFrJ   TpostOnlycrossz1 createOrder() is only available for cross margin)rZ  r   rX  r>   rY  r/  )r  r  handle_param_stringr+   r   cost_to_precisionamount_to_precisionr  r@  r  uuid16omitsafe_number_nis_post_onlyhandle_margin_mode_and_paramsr-   price_to_precisionv4PrivatePostOrderStopLimitr  )v4PrivatePostOrderCollateralTriggerMarketv4PrivatePostOrderStopMarket!v4PrivatePostOrderCollateralLimitv4PrivatePostOrderNew"v4PrivatePostOrderCollateralMarketv4PrivatePostOrderMarketv4PrivatePostOrderStockMarketr  )r	  r$  r  r  r.  r/  r  r  r  r6  rW  r   
marketTypeisLimitOrderisMarketOrderr   isStopOrderrZ  r   queryuseCollateralEndpointrj  s                         r  rM  whitebit.create_order  s   . 	V$Tl
 //?48#3"477-j#jkk $ 6 6v DGH $ 8 8 HGH**69oN ''jAH#+3kkm+C('4O$YYv'89F%%ff5
w())&2cd#4/$$]E6B >>}fU
E"&GJ!jG&;tww)\\]]5"KL *$ 6 N*:N*.*A*A&*WG&'#'#:#:6#I ;;DKK<XY )#MMdkkZaNjkH#@@WA]^H#'#:#:6#I (#EEdkkRYFbcH#99$++g:VWH )#FFt{{SZGcdH'#'#@#@WA]#^#'#E#EdkkRYFb#c))r  c                 :   U R                  5         U R                  U5      nSUS   0n	U R                  US5      n
U
b  XS'   OXS'   U R                  U/ SQ5      nUSLnU(       a  U R	                  X+5      U	S'   US:H  nU R                  US	5      nUb  U R                  X.5      U	S	'   OTUbQ  U(       a  U R                  X%5      U	S
'   O5US:X  a  US:X  a  U R                  X%5      U	S	'   OU R                  X%5      U	S
'   Ub  U R	                  X&5      U	S'   USL=(       d    USL=(       d    USL=(       d    USLnU(       d  [        U R                  S-   5      eU R                  U/ SQ5      nU R                  U R                  X5      5      nU R                  U5      $ )ar  
edit a trade order

https://docs.whitebit.com/private/http-trade-v4/#modify-order

:param str id: cancel order id
: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
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r   rW  Nr  )r   rX  activationPricerY  r   totalr.  rR  r/  zZ editOrder() requires at least one of: amount, price, activationPrice, or total parameters)rW  r   rX  ru  rv  )r  r  r@  ra  rd  rE  r^  r'   r   r`  v4PrivatePostOrderModifyr  r  )r	  r   r$  r  r  r.  r/  r  r  r  rW  r   rp  rn  rv  hasModifiableParamrj  s                    r  
edit_orderwhitebit.edit_orderO  s    	V$fTl
 ((A$'4O$!#I))&2bc#4/*.*A*A&*WG&'w  1#77FGG$($<$<V$L!!dem#'#;#;F#K  %)$<$<V$L!#66vEGG$D0}e46G}\aeMe}kpx|k|!#DGG  /K  %K  L  L6#mn00W1MN))r  c                     Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   [	        U5      S.nU R                  U R                  XS5      5      nU R                  U5      $ )aT  
cancels an open order

https://docs.whitebit.com/private/http-trade-v4/#cancel-order

: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
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
z) cancelOrder() requires a symbol argumentr   )r  r  )r'   r   r  r  intv4PrivatePostOrderCancelr  r  )r	  r   r$  r  r  r  rj  s          r  cancel_orderwhitebit.cancel_order  s{     >#DGG.Y$YZZV$Tl2w
 00W1MN( ))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X25      u  pR/ nUS:X  aC  SnU R                  USSS5      u  prU(       a  UR	                  S5        OHUR	                  S5        O6US	:X  a  UR	                  S
5        O[        U R                  S-   U-   S-   5      eXdS'   U R                  U R                  XB5      5      nU R                  X5      $ )a  
cancel all open orders

https://docs.whitebit.com/private/http-trade-v4/#cancel-all-orders

: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
:param str [params.type]: market type, ['swap', 'spot']
:param boolean [params.isMargin]: cancel all margin orders
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r  rA   r<   isMarginFr=   r>   r   z$ cancelAllOrders() does not support z typer  )
r  r  handle_market_type_and_paramsr  appendr-   r   v4PrivatePostOrderCancelAllr  parse_orders)	r	  r$  r  r  r  r  requestTyper  rj  s	            r  cancel_all_orderswhitebit.cancel_all_orders  s    	[[(F &tGH99:KV\6>H#<<VEVXbdijH""8,""6*V^y)tww)OORVVY``aa%33DKK4PQ   22r  c           	      
   U R                  5         [        R                  " U R                  XX45      U R	                  XX45      /6 u  pVU R                  XV5      nU R                  USS5      nUb  [        U5      U:  a  USU $ U$ )an  
fetches information on multiple orders made by the user(combines open and closed orders)

https://docs.whitebit.com/private/http-trade-v4/#query-unexecutedactive-orders
https://docs.whitebit.com/private/http-trade-v4/#query-executed-orders

: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>`
r  Tr   )r  r  r  fetch_open_ordersfetch_closed_ordersre  sort_byrb  )	r	  r$  r  r   r  
openOrdersclosedOrders	allOrderssortedOrderss	            r  fetch_orderswhitebit.fetch_orders  s     	#*>>""6%@$$VEB4
 $ 
 %%j?	||I{DA\!2U!:%((r  timeoutc                 f   U R                  5         U R                  US5      nUc  [        U R                  S-   5      eU R	                  U5      nU R                  US5      nUS:  nSUS   0nU(       a  U R                  US-  5      US'   OSUS'   U R                  U R                  Xb5      5      nU$ )	a  
dead man's switch, cancel all orders after the given timeout

https://docs.whitebit.com/private/http-trade-v4/#sync-kill-switch-timer

:param number timeout: time in milliseconds, 0 represents cancel the timer
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.types]: Order types value. Example: "spot", "margin", "futures" or None
:param str [params.symbol]: symbol unified symbol of the market the order was made in
:returns dict: the api result
r$  z< cancelAllOrdersAfter() requires a symbol argument in paramsr   r  r   r.  r  null)	r  r@  r'   r   r  r`  number_to_stringv4PrivatePostOrderKillSwitchr  )r	  r  r  r$  r  isBiggerThanZeror  rj  s           r  cancel_all_orders_after whitebit.cancel_all_orders_after  s     	!!&(3>#DGG.l$lmmV$68,#aKfTl
 !%!6!6w~!FGI!'GI44T[[5QR r  c                    [        UR                  5       5      n0 n[        S[        U5      5       H  nX$   nU R	                  U5      nX   n[        U[        5      (       aY  UbV  U R                  5       nU R                  USS5      US'   U R                  US5      US'   U R                  US5      US'   XU'   M  U R                  5       nXxS'   XU'   M     U R                  U5      $ )Nr   	availablemain_balancefreefreezeusedrv  )r_  r`  ra  rb  rA  r  dictr   r  r@  safe_balance)	r	  rj  balanceKeysrl  rm  r   r]  balancer   s	            r  parse_balancewhitebit.parse_balance  s    8==?+q#k*+AB**2.DlG'4((W-@,,."&"4"4Wk>"Z"&"2"27H"E#'#3#3G^#L &t,,.#* &t ,   ((r  c                    U R                  5         SnU R                  SSU5      u  p!SnUS:X  a  U R                  U5      nOU R                  U R                  S0 5      nU R                  US5      nU R                  USSU5      nU R                  USS/5      nUS:X  d  US:X  a  U R                  U5      nOU R                  U5      nU R                  U5      $ )a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://docs.whitebit.com/private/http-main-v4/#main-balance
https://docs.whitebit.com/private/http-trade-v4/#trading-balance

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
NrR   r>   r   r  r   r   )r  r  %v4PrivatePostCollateralAccountBalancerB  r  r@  r  r`  v4PrivatePostMainAccountBalance v4PrivatePostTradeAccountBalancer  )r	  r  rm  rj  r  defaultAccountr   s          r  fetch_balancewhitebit.fetch_balance,  s     	
!??PTV\]
AA&IHoodllNBGG!--gyAN((FNSGYYv	6':;F& Gy$8??G@@H. !!(++r  c                     U R                  5         Sn0 nUb  U R                  U5      nUS   US'   Ub  [        US5      US'   U R                  U R	                  Xd5      5      nU R                  XuX#SS05      $ )a  
fetch all unfilled currently open orders

https://docs.whitebit.com/private/http-trade-v4/#query-unexecutedactive-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
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r  r   r   rA  r  )r  r  r1  r  r  r  r  s           r  r  whitebit.fetch_open_orders]  s     	[[(F &tGH"5#GG++DKK,HI*   5(FASTTr  c           	      f   U R                  5         0 nSnUb  U R                  U5      nUS   nUS   US'   Ub  [        US5      US'   U R                  U R	                  XT5      5      n[        UR                  5       5      n/ n	[        S[        U5      5       Hq  n
X   nU R                  USS5      nX{   n[        S[        U5      5       H:  nU R                  X   U5      nU	R                  U R	                  US	S
05      5        M<     Ms     U R                  U	S5      n	U R                  XX#5      n	U	$ )a  
fetches information on multiple closed orders made by the user

https://docs.whitebit.com/private/http-trade-v4/#query-executed-orders

: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$  r   r  r   r   r   r  rA  closedr  )r  r  r1  r  r  r_  r`  ra  rb  r  r  r  r  filter_by_symbol_since_limit)r	  r$  r  r   r  r  r  rj  r  r  rm  r  r  r   rw  r  s                   r  r  whitebit.fetch_closed_orders  s2    	[[(FH%F &tGH"5#GG==dkk'>Z[$ )	q#i.)A |H((4=I'F1c&k*((I>t{{58X2FGH +	 * ,,w433GURr  c                 :    SSSSSSSS.nU R                  X!U5      $ )Nr   r  )r   r  stop marketz
stop limitzstock marketzmargin limitzmargin marketr@  )r	  r  typess      r  parse_order_typewhitebit.parse_order_type  s3    #!$#%
 T22r  r  c                    U R                  US5      nU R                  X2S5      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S:X  a  S nU R                  US	5      n	U R                  US
5      n
U R                  USS5      nU R                  US5      nU R	                  U5      nUS:X  a  S nU R                  US5      nU R                  US5      nUS:X  a  US:X  d  US:X  a  UnU R                  US5      nS nUb  U R                  U5      US   S.nU R                  USS5      nU R                  US5      nU R                  0 SU_SU_SU_SU_SU_SU R                  U5      _SU_SS _SS _SS _SU_S	U	_SU_SU
_SU_SU_S U_S UUS S!.EU5      $ )"Nr  r  r$  r  	dealStockleftrW   r/  rY  r  r   r  r.  	dealMoneyrR  r  dealFeer&  r"  ctimer  ftimer?  r  lastTradeTimestampr   rZ  rA  r   filled	remaining)r  r6  r   trades)
r@  r  rE  r  r  r  r$  r  
safe_orderr'  )r	  r  r  r  r$  r  r  r  rW  r/  r   r  r  	orderTyper.  r6  r  r   r  r  s                       r  r  whitebit.parse_order  s   P ##E84!!(C8!v.!!%5$$UF3	((@B M  0''/AB$$UIt<v.))$/	 I!!%2{3EM!1t}7LF""5)4))'2"7OC ))%+F	!00@  
E 
' 
 f 
 ]	 

  
 Y/ 
 !"4 
 4 
  
 d 
 D 
 U 
 I 
 L 
 f 
  f! 
" # 
$ + 
, - 	r  c                 $   U R                  5         S[        U5      0nSnUb  U R                  U5      nUS   US'   Ub  [        US5      US'   U R	                  U R                  Xe5      5      nU R                  US/ 5      n	U R                  X5      $ )a  
fetch all the trades made from a single order

https://docs.whitebit.com/private/http-trade-v4/#query-executed-order-deals

:param str id: order id
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
r  Nr   r  r   r   records)r  r|  r  r1  v4PrivatePostTradeAccountOrderr  rd  r  )
r	  r   r$  r  r   r  r  r  rj  r  s
             r  fetch_order_tradeswhitebit.fetch_order_trades%	  s     	s2w
 [[(F &tGH"5#GG66t{{77ST( ~~h	26  ..r  r]  c                 (   U R                  5         Sn0 nUb  U R                  U5      nUS   US'   Ub  U R                  US-  5      US'   Ub  US:  a  SnUb  X6S'   SUS	'   U R                  U R	                  Xd5      5      nU R                  XuX#5      $ )
af  
fetch all withdrawals made from an account

https://docs.whitebit.com/private/http-main-v4/#get-depositwithdraw-history

: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
:param str [params.transactionMethod]: transaction method(1=deposit, 2=withdrawal) - automatically set to '2' for withdrawals
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr   r   r.  	startDater   r   2transactionMethodr  rn  r0  v4PrivatePostMainAccountHistoryr  parse_transactionsr	  r]  r  r   r  rn  r  rj  s           r  fetch_withdrawalswhitebit.fetch_withdrawalsS	  s     	}}T*H (GH#'#4#4UT\#BGK =ECKE$G'*#$77G8TU& &&x5HHr  c                    U R                  5         Sn0 nUb  U R                  U5      nUS   US'   Ub  U R                  US-  5      US'   Ub  US:  a  SnUb  X6S'   U R                  U R	                  Xd5      5      nU R                  XuX#5      $ )af  
fetch history of deposits and withdrawals

https://docs.whitebit.com/private/http-main-v4/#get-depositwithdraw-history

:param str [code]: unified currency code
:param int [since]: the earliest time in ms to fetch transactions for
:param int [limit]: the maximum number of transactions structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.transactionMethod]: transaction method(1=deposit, 2=withdrawal) - automatically set to '1' for deposits
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr   r   r.  r  r   r   r  r  s           r  fetch_transactionswhitebit.fetch_transactions	  s     	}}T*H (GH#'#4#4UT\#BGK =ECKE$G77G8TU& &&x5HHr  c                    U R                  5         U R                  U5      nSUS   0nSnU R                  U5      (       a  U R                  US5      nUc  [	        U R
                  S-   5      eXdS'   U R                  US5      nUc  [	        U R
                  S-   5      eXtS'   U R                  US5      nUc  [	        U R
                  S	-   5      eU R                  U R                  XB5      5      nO U R                  U R                  XB5      5      nU R                  US
5      n	U R                  US0 5      n
U R                  U
SU	5      nU R                  U
S5      nU R                  U5        UUSUUS.$ )a  
fetch the deposit address for a currency associated with self account

https://docs.whitebit.com/private/http-main-v4/#get-fiat-deposit-address
https://docs.whitebit.com/private/http-main-v4/#get-cryptocurrency-deposit-address

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r   r   NproviderzB fetchDepositAddress() requires a provider when the ticker is fiatr.  zA fetchDepositAddress() requires an amount when the ticker is fiatuniqueIdzC fetchDepositAddress() requires an uniqueId when the ticker is fiatrD  r   addressmemor?  rn  rS  r  tag)r  rn  is_fiatr@  r'   r   rE  rB  &v4PrivatePostMainAccountFiatDepositUrlr  v4PrivatePostMainAccountAddresscheck_address)r	  r]  r  rn  r  rj  r  r.  r  rD  r   r  r  s                r  fetch_deposit_addresswhitebit.fetch_deposit_address	  s}    	==&htn
 <<''
;H'2v(vww"*J%%fh7F~'2u(uvv &Hvz:H'2w(wxxBB4;;wC_`H;;DKK<XYH6 x///(Ir:""7Is;w/7#
 	
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                  Xc5      $ )a  
create a currency deposit address

https://docs.whitebit.com/private/http-main-v4/#create-new-address-for-deposit

:param str code: unified currency code of the currency for the deposit address
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: the blockchain network to create a deposit address on
:param str [params.type]: address type, available for specific currencies
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r   r   r   )r  rn  (v4PrivatePostMainAccountCreateNewAddressr  rc  parse_deposit_addressr	  r]  r  rn  r  rj  r  s          r  create_deposit_addresswhitebit.create_deposit_address	  sn     	==&htn
 @@WA]^& ~~h	26))$99r  rn  c                 r    UU R                  S U5      S U R                  US5      U R                  US5      S.$ )Nr  r  r  )rA  r@  )r	  depositAddressrn  s      r  r  whitebit.parse_deposit_address 
  sD     #//h?''	B##NF;
 	
r  c           	      ~   U R                  5         / nU R                  U5      nU(       a  [        U[        5      (       a}  [	        S[        U5      5       Hd  nU R                  X45      nU R                  US5      nU R                  US5      nU(       d  MA  UR                  USU=(       d    SU-   SUS.5        Mf     U$ )a"  
fetch all the accounts associated with a profile

https://docs.whitebit.com/private/http-main-v4/#sub-account-list

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `account structures <https://docs.ccxt.com/#/?id=account-structure>`
r   r   r   
subaccountzSubAccount N)r   r  r   r]  r?  )	r  v4PrivatePostSubAccountListr  r_  ra  rb  rB  r@  r  )r	  r  accountssubAccountsrm  
subAccount	accountIdaccountNames           r  fetch_accountswhitebit.fetch_accounts/
  s     	 66v>:k4881c+./!__[<
 ,,Z>	"..z6B9OO' , + H}y/H $ *%  0 r  r   c                     U R                  5         Ub  [        U R                  S-   5      eUS:  d  US:  a  [        U R                  S-   5      eSU0nU R	                  U R                  XC5      5      $ )aJ  
set the level of leverage for a market

https://docs.whitebit.com/private/http-trade-v4/#change-collateral-account-leverage

: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
z/ setLeverage() does not allow to set per symbolr     z2 setLeverage() leverage should be between 1 and 20r   )r  r-   r   r(   &v4PrivatePostCollateralAccountLeverager  )r	  r   r$  r  r  s        r  set_leveragewhitebit.set_leverageU
  su     	tww)ZZ[[qLhmTWW'[[\\
 ::4;;w;WXXr  fromAccount	toAccountc                 \   U R                  5         U R                  U5      nU R                  U R                  S5      nU R	                  XsU5      nU R	                  XtU5      n	U R                  X5      n
US   U
UU	S.nU R                  U R                  X5      5      nU R                  X5      $ )a   
transfer currency internally between wallets on the same account

https://docs.whitebit.com/private/http-main-v4/#transfer-between-main-and-trade-balances

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account to transfer from - main, spot, collateral
:param str toAccount: account to transfer to - main, spot, collateral
: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   r.  fromto)	r  rn  rB  r  r@  currency_to_precision v4PrivatePostMainAccountTransferr  parse_transfer)r	  r]  r.  r   r  r  rn  r   fromAccountIdtoAccountIdamountStringr  rj  s                r  r   whitebit.transferm
  s     	==&7GH((kR&&~)L11$?tn"!	
 88W9UV ""866r  r   c           
      :    US S S U R                  S U5      S S S S S.	$ )N)	r?  r   r  r  rn  r.  r   r  rA  )rA  )r	  r   rn  s      r  r  whitebit.parse_transfer
  s6    
 //h?

 
	
r  r  r  c                    U R                  5         U R                  U5      nUS   U R                  X5      US.nU R                  US5      nUc  U R	                  5       nXS'   Ub  XGS'   U R                  U5      (       a1  U R                  US5      n	U	c  [        U R                  S-   5      eXS'   U R                  U R                  Xu5      5      n
U R                  SU0U R                  X5      5      $ )a  
make a withdrawal

https://docs.whitebit.com/private/http-main-v4/#create-withdraw-request

:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
r   )r   r.  r  r  r  r  z7 withdraw() requires a provider when the ticker is fiat)r  rn  r  rB  uuid22r  r'   r    v4PrivatePostMainAccountWithdrawr  parse_transaction)r	  r]  r.  r  r  r  rn  r  r  r  rj  s              r  r   whitebit.withdraw
  s     	==&tn00>

 ??6:6{{}H&
?!FO<<vz:H'2k(kll"*J88W9UV {{D(+T-C-CH-WXXr  transactionc                    U R                  S U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0 SU R                  US5      _SU R                  US	5      _S
U_SU R                  U5      _SU R                  US5      _SUS:X  a  UOS _SU_SUS:X  a  UOS _SU R	                  US5      _SUS:X  a  SOS_SU R                  XR5      _SU R                  U5      _SS _SS _SS _SS _SU R                  US5      _S U R	                  US5      U R                  XR5      S.US.E$ )Nr  	createdAtr   rA  r  r   r  txidtransactionIdr  r  rS  addressFrom1	addressTor  r.  r  rQ  
withdrawalrn  rB  tagFromr  tagTocommentdescriptionr   r"  )internalr   r?  )safe_currencyr@  r  r'  rE  rA  parse_transaction_status)r	  r  rn  r  r  r  rA  r  s           r  r  whitebit.parse_transaction
  s   @ %%dH5"";	:''[A	%%k8<
!!+x8!!+x8
$"";
;
D$$[/B
 
 Y/	

 t''Y?
 v}74
 w
 Vs]
 d&&{H=
 &C-Il
 //
E
 d33F;
 t
 t
 4
  T!
" t'']C#
$ ((e< 33JI  /
 	
r  rA  c                     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_nU R                  X!U5      $ )Nr  pendingr  3r@  4canceled56791011121314151617r  )r	  rA  statusess      r  r"  !whitebit.parse_transaction_status  s    


 
 	

 
 
 
 
 )
 )
 )
 )
 )
 )
 )
  )!
$ &99r  c                    U R                  5         SnSUSSS.nUb  U R                  U5      nUS   US'   U R                  U R                  XS5      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  X5      $ )ag  
fetch information on a deposit

https://docs.whitebit.com/private/http-main-v4/#get-depositwithdraw-history

:param str id: deposit id
:param str code: not used by whitebit fetchDeposit()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr  r   )r  r  r   offsetr   r   r  )r  rn  r  r  rB  rc  r  )	r	  r   r]  r  rn  r  rj  r  firsts	            r  fetch_depositwhitebit.fetch_deposit  s     	!"	
 }}T*H (GH77G8TUL //(Ir:w2.%%e66r  c                    U R                  5         SnSSSS.nUb  U R                  U5      nUS   US'   Ub  [        US5      US'   U R                  U R	                  Xd5      5      nU R                  US	/ 5      nU R                  XX#5      $ )
a  
fetch all deposits made to an account

https://docs.whitebit.com/private/http-main-v4/#get-depositwithdraw-history

: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>`
Nr  r   r   )r  r   r8  r   r   r   r  )r  rn  r1  r  r  rd  r  )	r	  r]  r  r   r  rn  r  rj  r  s	            r  fetch_depositswhitebit.fetch_depositsY  s     	!"

 }}T*H (GH"5#GG77G8TUL ..9b9&&w%GGr  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   U R                  U R                  Xe5      5      nU R	                  X5      n	U R                  XX45      $ )a)  
fetch the interest owed by the user for borrowing currency for margin trading

https://docs.whitebit.com/private/http-trade-v4/#open-positions

:param str code: unified currency code
:param str symbol: unified market symbol
: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>`
Nr   r  )r  r  +v4PrivatePostCollateralAccountPositionsOpenr  parse_borrow_interestsfilter_by_currency_since_limit)
r	  r]  r$  r  r   r  r  r  rj  interests
             r  fetch_borrow_interestwhitebit.fetch_borrow_interest  s{     	[[(F &tGHCCDKKPWD`a, ..x@2285PPr  r?  c                     U R                  US5      nU R                  X2S5      nU R                  US5      nUUSU R                  US5      SU R                  US5      SUU R	                  U5      S	.	$ )
Nr  r  
modifyDater  unrealizedFundinggXjP?r.  r[  )	r?  r$  rn  rC  interestRateamountBorrowedr   r  r  )r@  safe_symbolr  rE  r'  )r	  r?  r  r  r$  r  s         r  parse_borrow_interestwhitebit.parse_borrow_interest  s    ( ##D(3!!(C8''l;	((/BC#"..tX>!"Y/

 
	
r  c                     U R                  5         U R                  U5      nU R                  U/U5      nU R                  X15      $ )a@  
fetch the current funding rate

https://docs.whitebit.com/public/http-v4/#available-futures-markets-list

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
)r  r$  fetch_funding_ratesrB  )r	  r$  r  rj  s       r  fetch_funding_ratewhitebit.fetch_funding_rate  sA     	V$++VHf=x00r  c                     U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      nU R	                  XA5      $ )a  
fetch the funding rate for multiple markets

https://docs.whitebit.com/public/http-v4/#available-futures-markets-list

: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
rl  )r  r  v4PublicGetFuturesrd  parse_funding_rates)r	  r   r  rj  r  s        r  rO  whitebit.fetch_funding_rates  sV     	%%g.**62Z ~~h"5''66r  c                    U R                  US5      nU R                  X25      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	0 SU_SU_SU_SU_SU_S	S _S
S _SU_SU	_SU R	                  U	5      _SS _SS _SS _SS _SS _SS _SS _$ )N	ticker_id	markPrice
indexPricerI  funding_ratenext_funding_rate_timestampr?  r$  r  r  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer-  )r@  rK  rE  r%  r'  )
r	  r,  r  r  r$  rX  rY  rI  r\  fundingTimes
             r  parse_funding_ratewhitebit.parse_funding_rate4  s]   B ##Hk:!!(3$$X{;	%%h=
''.A&&x@''2OP
H
f
 
 *	

 L
 
 
 ;
 
 t||K8
 t
 #D
 "4
 "4
 '
  &t!
" #
 	
r  c                 8   U R                  5         Uc  [        U R                  S-   5      eU R                  U5      nSUS   0nUb  X&S'   Ub  X&S'   U R	                  SXd5      u  pdU R                  U5      nU R                  US/ 5      nU R                  XX#5      $ )a1  
fetch the history of funding payments paid and received on self account

https://docs.whitebit.com/private/http-trade-v4/#funding-history

: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>`
z1 fetchFundingHistory() requires a symbol argumentr  r   r  r   endDater  )r  r'   r   r  handle_until_option,v4PrivatePostCollateralAccountFundingHistoryrd  parse_funding_histories)	r	  r$  r  r   r  r  r  rj  r  s	            r  fetch_funding_historywhitebit.fetch_funding_historyp  s     	>#DGG.a$abbV$fTl
 #(K $G229gNDDWM$ ~~h	26++D%GGr  c           
          U R                  US5      nU R                  US5      nUU R                  X2S S5      S UU R                  U5      S U R	                  US5      S.$ )Nr  re  r>   fundingAmount)r?  r$  r]  r  r  r   r.  )r@  r%  rK  r'  rE  )r	  r,  r  r  r  s        r  parse_funding_historywhitebit.parse_funding_history  sl     ##Hh7%%h>	&&xvF"Y/&&xA
 	
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  )ra  rb  r  rq  r  r  )	r	  	contractsr  r  r   rl  rm  r,  sorteds	            r  rl   whitebit.parse_funding_histories  s_    q#i.)A |HMM$44XFG * fk2))&??r  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X5S'   U R                  U R                  XT5      5      nU R	                  US5      nU R                  XX#5      $ )a  
       fetch history of deposits and withdrawals

       https://github.com/whitebit-exchange/api-docs/blob/main/pages/private/http-main-v4.md#get-depositwithdraw-history

       :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 = 50, Min: 1, Max: 100
       :param dict [params]: extra parameters specific to the exchange API endpoint

EXCHANGE SPECIFIC PARAMETERS
       :param number [params.transactionMethod]: Method. Example: 1 to display deposits / 2 to display withdraws. Do not send self parameter in order to receive both deposits and withdraws.
       :param str [params.address]: Can be used for filtering transactions by specific address or memo.
       :param str[] [params.addresses]: Can be used for filtering transactions by specific addresses or memos(max: 20).
       :param str [params.uniqueId]: Can be used for filtering transactions by specific unique id
       :param int [params.offset]: If you want the request to return entries starting from a particular line, you can use OFFSET clause to tell it where it should start. Default: 0, Min: 0, Max: 10000
       :param str[] [params.status]: Can be used for filtering transactions by status codes. Caution: You must use self parameter with appropriate transactionMethod and use valid status codes for self method. You can find them below. Example: "status": [3,7]
       :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
       Nr   r   r   r  )r  rn  r  r  rd  r  )	r	  r]  r  r   r  r  rn  rj  r  s	            r  fetch_deposits_withdrawals#whitebit.fetch_deposits_withdrawals  s    ( 	}}T*H (GH$G77G8TUN ..95&&w%GGr  fromCodetoCodec                     U R                  5         U R                  U5      nU R                  U5      nUUU R                  U5      SS.nU R                  U R	                  Xt5      5      nU R                  XU5      $ )a  
fetch a quote for converting from one currency to another

https://docs.whitebit.com/private/http-trade-v4/#convert-estimate

:param str fromCode: the currency that you want to sell and convert from
:param str toCode: the currency that you want to buy and convert into
:param float amount: how much you want to trade in units of the from currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
r  )r  r  r.  	direction)r  rn  r  v4PrivatePostConvertEstimater  parse_conversion)	r	  rz  r{  r.  r  fromCurrency
toCurrencyr  rj  s	            r  fetch_convert_quotewhitebit.fetch_convert_quote  sz     	}}X.]]6*
++F3	
 44T[[5QR $$XZHHr  c                     U R                  5         U R                  U5      nU R                  U5      nSU0nU R                  U R                  X5      5      n	U R	                  XU5      $ )a)  
convert from one currency to another

https://docs.whitebit.com/private/http-trade-v4/#convert-confirm

:param str id: the id of the trade that you want to make
:param str fromCode: the currency that you want to sell and convert from
:param str toCode: the currency that you want to buy and convert into
:param float [amount]: how much you want to trade in units of the from currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
r)  )r  rn  v4PrivatePostConvertConfirmr  r  )
r	  r   rz  r{  r.  r  r  r  r  rj  s
             r  create_convert_tradewhitebit.create_convert_trade'  sh     	}}X.]]6*
r
 33DKK4PQ $$XZHHr  c                 P   U R                  5         0 nUb  XS'   Ub(  U R                  US-  5      nU R                  U5      US'   Ub  X5S'   U R                  SXTS5      u  pTU R	                  U R                  XT5      5      nU R                  US/ 5      nU R                  XSS	X#5      $ )
a  
fetch the users history of conversion trades

https://docs.whitebit.com/private/http-trade-v4/#convert-history

:param str [code]: the unified currency code
:param int [since]: the earliest time in ms to fetch conversions for
:param int [limit]: the maximum number of conversion structures to retrieve, default 20, max 200
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.until]: the end time in ms
:param str [params.fromTicker]: the currency that you sold and converted from
:param str [params.toTicker]: the currency that you bought and converted into
:param str [params.quoteId]: the quote id of the conversion
:returns dict[]: a list of `conversion structures <https://docs.ccxt.com/#/?id=conversion-structure>`

fromTickerr.  r  r   r  gMbP?r  r  r  )r  r0  r  rj  v4PrivatePostConvertHistoryr  rd  parse_conversions)	r	  r]  r  r   r  r  r/  rj  rowss	            r  fetch_convert_trade_history$whitebit.fetch_convert_trade_historyC  s      	$(L!%%edl3E"33E:GFO$G224%P33DKK4PQ0 ~~h	26%%d.,PU]]r  
conversionr  r  c                    U R                  US/ 5      nU R                  US0 5      nU R                  US5      nU R                  US5      nU R                  USS5      nU R                  USU5      n	U R	                  X5      n
U R                  USU5      nU R	                  X5      nUUU R                  U5      U R                  US5      U
U R                  USS	5      UU R                  US
S5      U R                  US5      S S.
$ )Npathr   r  r  dateexpireAtr   give	finalGivereceivefinalReceiverate)
r?  r  r  r   r  
fromAmountr  toAmountr/  r   )rd  rc  r@  r$  rA  r'  safe_number_2rE  )r	  r  r  r  r  r9  fromPathtoPathr  fromCoinrz  toCoinr{  s                r  r  whitebit.parse_conversionx  s   L ~~j&"5tQ+##E62!!%.))*fjI	##JA**8B!!*dF;((<"Y/"":t4$,,ZM **:y.Q%%j&9
 	
r  c                    U R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X&S'   U R                  SXd5      u  pdU R                  U R	                  Xd5      5      nU R                  U5      nU R                  XX#5      $ )a  
fetches historical positions

https://docs.whitebit.com/private/http-trade-v4/#positions-history

:param str symbol: unified contract symbol
:param int [since]: the earliest time in ms to fetch positions for
:param int [limit]: the maximum amount of records to fetch
:param dict [params]: extra parameters specific to the exchange api endpoint
:param int [params.positionId]: the id of the requested position
:returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
r  r   r  r   ri  )r  r  rj  .v4PrivatePostCollateralAccountPositionsHistoryr  parse_positionsr  )	r	  r$  r  r   r  r  r  rj  	positionss	            r  fetch_position_historywhitebit.fetch_position_history  s     	V$fTl
 #(K $G229gNFFt{{SZGcd0 ((2	00EQQr  c                     U R                  5         U R                  U5      nU R                  U5      nU R                  X15      $ )aB  
fetch all open positions

https://docs.whitebit.com/private/http-trade-v4/#open-positions

:param str[] [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>`
)r  r  r@  r  )r	  r   r  rj  s       r  fetch_positionswhitebit.fetch_positions  sC     	%%g.CCFK, ##H66r  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                  Xc5      $ )aj  
fetch data on a single open contract trade position

https://docs.whitebit.com/private/http-trade-v4/#open-positions

:param str symbol: unified market symbol of the market the position is held in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
r$  r   r   )r  r  r@  r  rc  parse_position)r	  r$  r  r  r  rj  r  s          r  fetch_positionwhitebit.fetch_position
  so     	V$fTl
 CCDKKPWD`a, ~~h2.""400r  positionc                    U R                  US5      nU R                  US5      nU R                  US0 5      nU R                  US0 5      nU R                  0 SU_SU R                  US5      _SU R	                  X25      _S	S _S
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U R                  US5      _SS _SS _SS _SS _SS _SS _SU_U R                  U5      U R                  US5      S S U R                  US5      S S S S U R                  US5      U R                  US5      S.E5      $ )Nr  openDatetpslorderDetailr?  r   
positionIdr$  notionalr   liquidationPrice
entryPrice	basePriceunrealizedPnlpnlrealizedPnlr   
pnlPercentrt  r7  rX  r  r  r   r  rG  r=   stopLoss
takeProfit)r  lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentager   initialMargininitialMarginPercentager   marginRatior   r   )r@  r  rc  safe_positionrK  rE  r'  )r	  r  r  r  r  r  r  s          r  r  whitebit.parse_position2  s   X ##Hh7''*=	~~h3nnX}bA!! #
H#
$""8\:#
 d&&x8#
 	#

 $#
  0 0;M N#
 $**8[A#
 T--h>#
 4++KG#
 $**8\B#
 #
 D#
 #
 #
 D#
  d!#
" ##
$ Y/#'#6#6x#N!%+/**8X>!'+!--dJ?#//lC9#
  	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                  Xc5      $ )aQ  
fetch the rate of interest to borrow a currency for margin trading

https://docs.whitebit.com/private/http-main-v4/#get-plans

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `borrow rate structure <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
r   r   r   )r  rn  "v4PrivatePostMainAccountSmartPlansr  rd  parse_borrow_rater  s          r  fetch_cross_borrow_rate whitebit.fetch_cross_borrow_rate  sn     	==&htn
 ::4;;w;WX ~~h2.%%d55r  c                     U R                  US5      nU R                  US5      nU R                  X25      U R                  [        R                  " US5      5      U R                  US5      S S US.$ )Nr   r  r"  duration)rn  r  periodr  r  r?  )r@  rA  r  r1   rD  r%  )r	  r?  rn  r  r  s        r  r  whitebit.parse_borrow_rate  st     %%dH5
""43//
E%%g&8&8%&HI''j9
 	
r  c                 ^    U R                  U R                  S/ 5      nU R                  X5      $ )Nr   )rB  r  rg  )r	  rn  r   s      r  r  whitebit.is_fiat  s(    7GL}}X66r  c                 B    U R                  5       U R                  S   -
  $ )Nr   )millisecondsr  )r	  s    r  noncewhitebit.nonce  s       "T\\2B%CCCr  r   GETc                    U R                  X@R                  U5      5      nU R                  US5      nU R                  US5      n	Uc  0 nSU R                  -   S-   U R                  -   US'   SU R                  X5      -   n
U R                  S   U   U	   U
-   nU	S:X  a  U(       a  US	U R                  U5      -   -  nU	S
:X  a  U R                  5         [        U R                  5       5      nU R                  U R                  5      nSU-   U
-   nU R                  U R                  XS.U5      5      nU R                  U5      nU R!                  U R                  U5      U["        R$                  5      nSU R&                  UUS.nXXeS.$ )Nr   r  zccxt/-z
User-Agentr  r   r   ?r   z/api/)r  r  zapplication/json)zContent-TypezX-TXC-APIKEYzX-TXC-PAYLOADzX-TXC-SIGNATURE)rD  r  bodyheaders)r`  extract_paramsrB  r   r   implode_paramsr   	urlencodecheck_required_credentialsstrr  encodesecretjsonr  string_to_base64hmachashlibsha512apiKey)r	  r  r   r  r  r  r  rq  r   accessibilitypathWithParamsrD  r  r  r  payload	signatures                    r  signwhitebit.sign  so   		&"5"5d";<//#q)Q/?G '$'' 1C 7$,, Ft224@@iiw'6GH$sT^^E222I%++-

%E[[-F''1NBG99T[[W)MvVWD++D1G		$++g"6OI 2 $!(#,	G dOOr  reasonrD  r  r  r  c
                 b   US:X  d  US:X  a0  [        U R                  S-   [        U5      -   S-   U-   S-   U-   5      eUS:X  a'  [        U R                  S-   [        U5      -   S-   5      eUGbB  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
S L=(       a    U
S
:g  =(       a    US LnU(       d  Ub  U R                  S-   U-   nUnU(       a  U
nOmU R                  US0 5      n[        UR                  5       5      n[        U5      nUS:  a0  US   nU R                  UU/ 5      n[        U5      nUS:  a  US   OUnU R                  U R                  S   UU5        U R                  U R                  S   Xo5        [        U5      eg )Ni  i  r  i  z endpoint not foundrA  errorsmessager]  200r   r   r   )r.   r   r  r$   r@  rB  r%  rc  r_  r`  rb  throw_exactly_matched_exceptionr  throw_broadly_matched_exception)r	  r]  r  rD  r  r  r  rj  requestHeadersrequestBodyrA  r  r  codeNewhasErrorStatusfeedback	errorInfoerrorObject	errorKeyserrorsLengtherrorKeyerrorMessageArrayerrorMessageLengths                          r  handle_errorswhitebit.handle_errors  s   CKTS[ 3T!:S!@6!IC!ORV!VWW3;#D	 9<Q QRR %%h9F__Xx8F&&x;G ''&9G#4/ZFeOZVZHZN!477S=4/#	! &I"&..8R"HK $[%5%5%7 8I#&y>L#a'#,Q<,0OOKSU,V)-01B-C*=ORS=S$5a$8Z^	44T__W5MyZbc44T__W5Mt^#H--r   )NN)N)NNN)s__name__
__module____qualname____firstlineno__r   r  r#   r   r  r  rJ  r   rz  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_  r4  r<  rF  rJ  r   floatrO  rS  r   r   rM  ry  r~  r  r  r  r   r  r  r  r  r  r  r  r!   r  r  r   r  r  r   r  r   r  r|  r  r"   r   r  r   r  r"  r:  r=  r   rD  rL  r   rP  r   rO  rf  r   rm  rq  rl  rx  r
   r  r  r  r  r   r  r  r  r  r   r  r  boolr  r  r  r  __static_attributes____classcell__)r
  s   @r  r3   r3      s	   e# eN $& #+$v, #+JU
4 U
F U
n ') LZ L\ 7;2 5
G 5
n <@ 6A 6ApV#p )+ -{ -^ 7;2 dG d# dL 59 I' IV 02 "13 "1f "1HO4 O O6 Ob 26b ;Nc ;N3 ;NU ;Nz 04B *GW *G7 *GX :>b 'Bs 'B3 'BY 'BR 6:UW A3 As A# A\`af\g A@ -1tRV_a DRc DR DRC DRLN Nv N N` 9=4^bkm )J# )J# )JS )JX[ )Jrvw{r| )JV
 
4 
* #% 
0 !# 3s 3" _a \C \y \PU \ RT O O5 OX] O gksu X*3 X*i X*y X*RW X*`c X*t `drv  @B 7*S 7*# 7*Y 7*i 7*Y\ 7*lo 7*r 37r '*s '*C '*R /32 %3 %3N *.Dt\^ 3 c  cghmcn 6 <> $s $L) )& $& /,( /,b /3TXac )U )U3 )Uc )Uhlmrhs )UV 154VZce 2# 2S 2PS 2jnotju 2h
3S 
3[ [v [ [z 9=4^bkm ,/S ,/# ,/S ,/X[ ,/\ -1tRV_a .Ic .I .IC .Ifjkvfw .I` .2SW`b -Is -I# -IS -Igklwgx -I^ 79 E
# E
^ E
N 8: %:3 %:n %:N
h 
R` 
 %' $4= $L 9=R YS Y# Y0 [] 7S 7% 7c 7c 7an 7>
t 
x 
= 
  KOWY &YS &Y% &Y# &YC &Y^i &YP>
T >
X >
Q\ >
@:s :* 26b >7 >73 >7@ *.Dt\^ ?H3 ?Hc ?H ?Hcghsct ?HB 15DW[jnwy *Q# *Qc *QQT *Qdg *Q  C  DR  S *QX!
$ !
 !
. !
F 68 1 1K 1 6:" :77 :7 :7x:
6 :
[ :
x 37TX\eg ,HC ,Hs ,HRU ,Hlpq  mA ,H\
f 
0@S @X[ @gklzg{ @ 6:[_hj DHs DH# DHUX DHost  pA DHL MQY[ !IC !I !Ic !I`j !IF W[ce Is Ic I3 IPS Ijt I8 7;\`ik 3^ 3^3 3^VY 3^ptu  qA 3^j:
4 :
x :
\d :
pz :
x @DRV_a 0RS 0R 0RC 0Rfjksft 0Rd 26b "7w "7T(^ "7H 24 &1S &1 &1PMt MV Mx M^ 9; 6C 6 6*
 
7 7 7D &eBSW P8!# !s ! !c !TX !`c ! !r  r3   )9ccxt.base.exchanger   ccxt.abstract.whitebitr   r  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!   r"   typingr#   ccxt.base.errorsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   ccxt.base.decimal_to_precisionr0   ccxt.base.preciser1   r3   r  r  r  <module>r     s    ( .   V  V  V  V  V  V  V  V  * 0 - . ' & . ) * ) + 1 4 %L;x L;r  