
    !:hM                    l   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z& d dl%m'Z' d dl%m(Z( d d	l%m)Z) d d
l%m*Z* d dl%m+Z+ d dl%m,Z, d dl%m-Z- d dl%m.Z. d dl%m/Z/ d dl%m0Z0 d dl%m1Z1 d dl2m3Z3 d dl4m5Z5  G d dee      Z6y)    )Exchange)ImplicitAPIN)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                   V    e Zd Zdef fdZi fdee   fdZdedefdZ	i fde
fdZdi fdefd	Zdi fdefd
ZdndZi fdefdZi fdedefdZdodededefdZdi fdedefdZdi fdededefdZddi fdedededee   fdZdddi fdededefdZdodededefdZdddi fdedededee    fdZ!dodede fdZ"i fdZ#i fdefdZ$i fdede%d e&fd!Z'i fded e&de(fd"Z)di fded#e*de%d$e&d%e+f
d&Z,ddi fd'eded#e*de%d$e+d%e+fd(Z-di fd'edefd)Z.di fdefd*Z/i fd+efd,Z0de1fd-Z2i fde1fd.Z3dddi fdedededee(   fd/Z4dddi fdedededee(   fd0Z5d#efd1Z6dod2edede(fd3Z7dddi fd'edededefd4Z8i fd5ede9fd6Z:i fd5ede9fd7Z;dod8e<de9fd9Z=di fd:edefd;Z>i fd5ed$e&d<ed=ede?f
d>Z@dod?ed8e<de?fd@ZAdi fd5ed$e&dAedeBfdBZCdodCed8e<deBfdDZDdEefdFZEdi fd'ed5efdGZFdddi fd5edededeeB   fdHZGddddi fd5ededededeeH   f
dIZIdodJededeHfdKZJi fdedeKfdLZLdi fdedeMfdMZNdodedeKfdNZOdddi fdedededeeP   fdOZQdodefdPZRdpdededeeP   fdQZSdddi fd5edededeeB   fdRZTdi fdSedTed$e+deUfdUZVdi fd'edSedTed$e+deUf
dVZWdddi fd5edededeeU   fdWZXdndXedYe<dZe<deUfd[ZYddi fdedededeeZ   fd\Z[di fdedeeZ   fd]Z\i fdedeZfd^Z]dod_ededeZfd`Z^i fd5ede_fdaZ`dod8e<fdbZad8edebfdcZcdd Zddedfi ddfdgZed5efdhediedjedkedlefdmZg xZhS )qwhitebitreturnc                     | j                  t        t        |          ddddgddi dd ddd	dd
dddddddddddddddddddddddddddi ddddddddddddddd dd!dd"dd#dd$dd%dd&dd'dd(dd)di d*dd+dd,dd-dd.d/d0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;di d<dd=dd>dd?dd@ddAddBddCddDddEddFddGddHddIddJddKddLddddddddMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcidddedadfdgdhdidjdkdldmgidlg dnidog dpidadbdlg dqiidlg dridog dsidadtdudd| j	                  dv      | j	                  dv      dwidxdg dydzdid{d{dd|dd}d~didddddddd ddd dddddddddddddd ddd d ddd ddddddd ddd d d ddddddid	ddiddiddidd d ddt
        t        t        t        t        t        t        t        t        t        t        t        t        t        t        dt        t        t        t        t        t        t        ddd      S )Nr2   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fetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrdersfetchOrderBookfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFees)fetchTransactionFees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v2r6   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/orderztrade-account/order/historyz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   r6   tradingz0.001)	tierBased
percentagetakermakerr   )EURUSDRUBUAHaccountmain
collateral)fundingr   r:   r;   tradeBEP20BSCccxt)timeDifferenceadjustForTimeDifferencefiatCurrenciesrO   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)r   r   triggerr   r   )r   r   r   daysBackCanceledr   r   r   r   r     )	sandboxrH   createOrdersrl   
fetchOrderro   fetchOrdersrR   rm   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superr2   describeparse_numberr/   r$   r(   r'   r*   r)   r%   r+   r.   )self	__class__s    U/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/whitebit.pyr   zwhitebit.describe   s   h > @KKK $K 	K
 %K %K "4K 'K tK K %dK 'K /K ,UK 0K  t!K" &t#K$ '%K& ('K( "4)K* %d+K, U-K. /K0 +E1K2 )%3K4 $T5K6 $T7K8 $U9K: +D;K< '=K> (?K@ "4AKB CKD &tEKF (GKH 1%IKJ  KKL +DMKN *:OKP +DQKR &tSKT #DUKV *5WKX $TYKZ "5[K\ *5]K^ +E_K` "5aKb cKd !%eKf  gKh diKj +EkKl "4mKn !$oKp #DqKr  sKt 'uKv $UwKx !$yKz )%{K| t}K~ tK@ AKB TCKD tEKF "5GKH #DIKJ )-$)',#  UKZ $ ~ #G#@
 !"F #G#@ 2F;`%, (   
  	! 4   	   $  L!N %aWM^ !&"&!..w7!..w7	 #$+0">v!  &""*## U!  &"%,  %&*(,,1,0).+06:#'#("&#(	( #($)$)+/27/4#()$, %)&+!$$(%)*/& #'&+!$#($)*/( $(&+!$$(,0%)#($)*/	*  #g6p y
 "9 "9 	 ##GGP ' .A5>/8(25A+<7C*;4DN^7D5?/(" 4D<H'3*60<7G@Q#WFC
 F F	    c                    K   | j                   d   r| j                          d{    | j                          d{   }| j                  |      S 7 -7 w)a  
        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   N)r   load_time_differencev4PublicGetMarketsparse_markets)r   paramsr   s      r  fetch_marketszwhitebit.fetch_markets  sT      <<12++---//110 !!'**3 .1s   #AAAAAAmarketc                 j   | j                  |d      }| j                  |d      }| j                  |d      }|dk(  rdn|}| j                  |      }| j                  |      }| j                  |d      }| j                  |d      }| j                  |d      }	d }
d }|d	z   |z   }|	d
k(  }|xr | }d}| j                  | j	                  | j                  |d                  }|}d }d }|r$|}| j                  |      }
|dz   |
z   }d}d}d}d}nd}| j                  |d      }t        j                  |d      }| j                  |d      }t        j                  |d      }i d|d|d|d|d|
d|d|d|d|d| d|d|ddddd|d |d!||| j                  |      | j                  |      |d d d d || j                  | j	                  | j                  |d"                  d#d d d$| j                  |d%      d d$d d d$| j                  |d&      | j                  |d'      d$d(d |d)S )*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_precisionr0   
string_divsafe_number)r   r	  r   r  r  r  r  r  r  typeIdr  r  r  r<   r;   r   amountPrecisionr+  r   r   r  takerFeeRater   makerFeeRater   s                            r  parse_marketz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                   K   | j                  |       d{   }t        |j                               }i }t        dt	        |            D ]  }||   }||   }| j                  |dd      }| j                  |dd      }	|xr |	}
| j                  |      }d|v }|||d|
||	dd|rdnddddd	| j                  |d
      | j                  |d      d	dd||<    |S 7 ŭw)a  
        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
        Nr   can_depositTcan_withdraw	providersfiatcryptor$  min_withdrawmax_withdraw)r"  r   )r   coder3  r   r  depositr   r   networksr  r0  r1  )v4PublicGetAssetslistkeysrangelen	safe_boolr5  r9  )r   r  responseidsresultir   currency
canDepositcanWithdrawr  rG  hasProviders                r  fetch_currencieszwhitebit.fetch_currencies"  s      //77D 8==?#q#c(#  	AQB|H -FJ..>4HK/KF**2.D&(2K  %' "-8!  $#
  $//.I#//.I!	F4L 	B K 8s   CCCCNcodesc                   K   | j                          d{    | j                  |       d{   }t        |j                               }i }i }t	        dt        |            D ]m  }||   }||   }	| j                  |      }
| j                  |	di       }| j                  |d      ||
<   | j                  |	di       }| j                  |d      ||
<   o |||dS 7 7 w)ay  
 @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>`
        Nr   r   fixedrH  )r   rH  r3  )	load_marketsv4PublicGetFeerK  rL  rM  rN  r5  r6  r4  )r   rY  r  rP  currenciesIdswithdrawFeesdepositFeesrS  rT  datarG  r   rH  s                r  fetch_transaction_feeszwhitebit.fetch_transaction_fees  s      !!!,,V444 X]]_-q#m,- 	CA$Q'HH%D**84DtZ<H!%!1!1(G!DLoodIr:G $ 0 0' BK	C %"
 	
M 	"4s    C CC CB-C C c                    K   | j                          d{    | j                  |       d{   }| j                  ||      S 7 /7 w)ad  
        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>`
        N)r\  r]  parse_deposit_withdraw_fees)r   rY  r  rP  s       r  fetch_deposit_withdraw_feesz$whitebit.fetch_deposit_withdraw_fees  sM      !!!,,V44V //%@@Y 	"4s   A
AA
AA
A
c                    i }| j                  |      }t        |j                               }t        dt	        |            D ].  }||   }|j                  d      }|d   }	||   }
| j                  |	      }|| j                  ||      sJ| j                  ||      }|| j                  i       ||<   |
||   d   |<   | j                  |d      }| j                  |
d      }| j                  |
d      }| j                  |d      }| j                  |d      }||dnd d	}||dnd d	}|4t	        |      }|d|dz
   }| j                  |      }||d
||   d   |<   |||   d<   |||   d<   1 t        |j                               }t        dt	        |            D ]0  }||   }| j                  |      }| j                  ||   |      ||<   2 |S )Nr    r3     r   rH  r[  F)r   r   )r   rH  rI  )market_codesrK  rL  rM  rN  splitr5  in_arrayr6  deposit_withdraw_feer4  r9  network_id_to_coderT  $assign_default_deposit_withdraw_fees)r   rP  rY  currencyIdKeydepositWithdrawFeescurrencyIdsrS  entry
splitEntry
currencyIdfeeInforG  depositWithdrawFee	networkIdr   rH  withdrawFee
depositFeewithdrawResultdepositResultnetworkLengthnetworkCodedepositWithdrawCodesrT  s                           r  rd  z$whitebit.parse_deposit_withdraw_fees  s@   V %'!!%(8==?+q#k*+ "	IANES)J#AJuoG**:6D4==u#=%)__5H$%O"%-040I0I"0M'-;B#D)&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"	IF  $$7$<$<$>?q#234 	wA'*D}}T*H(,(Q(QRefjRkmu(v%	w #"r  c           	      *  K   | j                          d{    | j                  |       d{   }i }t        dt        | j                              D ]  }| j                  |   }| j                  |      }| j                  ||d   i       }| j                  |d      }| j                  |d      }	t        j                  |d      }t        j                  |	d      }	||d   dd	| j                  |      | j                  |	      d
||<    |S 7 7 w)aV  
        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
        Nr   r  	maker_fee	taker_feer  r  TF)r3  r  r   r   r   r   )r\  rJ  rM  rN  r   r	  r6  r4  r0   r8  r   )
r   r  rP  rR  rS  r  r	  r   r  r  s
             r  fetch_trading_feeszwhitebit.fetch_trading_feesY  s     !!!//77$ q#dll+, 	A\\!_F[[(F//(F8,<bAC''[9H''[9H))(E:H))(E:H *""**84**84F6N	  I 	"7s    DDDDC DDr  c                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |di       }| j                  ||      S 7 j7 +w)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>`
        Nr	  r   rR  )r\  r	  v1PublicGetTickerextend	safe_dictparse_ticker)r   r  r  r	  requestrP  r   s          r  fetch_tickerzwhitebit.fetch_ticker  s      !!!V$fTl
 //GV0LMM$ (B7  001 	"
 N"   BBA BB*BBr   c           	      @   | j                  |d      }| j                  ||      }| j                  |g d      }| j                  |d|      }| j                  i d|d   dd dd d| j                  |d      d| j                  |d      d	| j	                  |d	d
      dd d| j	                  |dd      dd dd d| j                  |d      d|d|dd dd d| j                  |d      dd | j                  |g d      | j                  |g d      |d|      S )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quoteVolumer3  )r4  safe_marketsafe_string_nsafe_tickersafe_string_2)r   r   r	  marketIdr  r  s         r  r  zwhitebit.parse_ticker  s   h ##FN;!!(F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                 V  K   | j                          d{    | j                  |      }d}| j                  |dd|      \  }}d}|dk(  r| j                  |       d{   }n| j	                  |       d{   }| j                  |d      }|| j                  ||      S t        |j                               }i }t        dt        |            D ]7  }||   }	| j                  |	      }
| j                  ||	   |
      }|d   }|||<   9 | j                  |d|      S 7 7 7 w)a  
        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>`
        Nv4PublicGetTickerry   methodrR  r   r  )r\  market_symbolshandle_option_and_paramsr  v2PublicGetTicker	safe_listparse_tickersrK  rL  rM  rN  r  r  filter_by_array_tickers)r   r   r  r  rP  
resultList	marketIdsrR  rS  r  r	  r   r  s                r  fetch_tickerszwhitebit.fetch_tickers  sA     !!!%%g.$66v~xY_`((!33F;;H!33F;;H ^^Hh7
!%%j'::)	q#i.) 	$A |H%%h/F&&x'96BFH%F#F6N	$ ++FHgFF? 	" <;s5   D)D"A	D) D%!D):D';B(D)%D)'D)r   c                   K   | j                          d{    | j                  |      }d|d   i}|||d<   | j                  | j                  ||             d{   }| j	                  |d      }| j                  |||      S 7 q7 +w)a1  
        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
        Nr	  r   r   r  )r\  r	  v4PublicGetOrderbookMarketr  safe_timestampparse_order_book)r   r  r   r  r	  r  rP  r  s           r  fetch_order_bookzwhitebit.fetch_order_book)  s      !!!V$fTl
 $GG88Wf9UVV( ''+>	$$XvyAA9 	" Ws"   BBABB
*B
Bsincec                    K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  ||||      S 7 Y7 w)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>`
        Nr	  r   )r\  r	  v4PublicGetTradesMarketr  parse_tradesr   r  r  r   r  r	  r  rP  s           r  fetch_tradeszwhitebit.fetch_tradesR  s}      !!!V$fTl
 55dkk'66RSS   65%@@% 	"
 Ts"   A4A0A A4A2A42A4c                 v  K   | j                          d{    d}i }|| j                  |      }|d   |d<   | j                  | j                  ||             d{   }t	        |t
              r| j                  ||||      S g }t        |j                               }	t        dt        |	            D ]S  }
|	|
   }| j                  |dd      }| j                  ||g       }| j                  ||||      }| j                  ||      }U | j                  |dd      }| j                  |||d      S 7 7 حw)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	  (v4PrivatePostTradeAccountExecutedHistoryr  
isinstancerK  r  rL  rM  rN  r  r6  array_concat	sort_by_2filter_by_since_limit)r   r  r  r   r  r	  r  rP  resultsrL  rS  r  	marketNew	rawTradesparseds                  r  fetch_my_tradeszwhitebit.fetch_my_tradesr  sH     !!![[(F &tGHFFt{{SZ\bGcddL h%$$XvueDDG(D1c$i( =7 ,,XtSA	 OOHhC	**9iN++GV<= nnWk4@G--gue[QQq 	" es#   D9D4AD9D7CD97D9r   c                 F   | j                  d |      }| j                  |dd      }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d	d
      }| j                  |dd      }	|d   }
| j	                  |d      }d }|	|dk(  rdnd}d }| j                  |d      }|$|| j                  | j                  |d            d}| j                  ||| j                  |      |
||d ||	||||d|      S )Nr   trade_timestampdealOrderIdorderIdr  r#  r"  r  r   tradeIDr  sider  rolerh  r   r   r   feeAssetr*  rT  )r3  r  r  r  r   orderr  takerOrMakerr  r#  r"  r*  r   )r  safe_timestamp_2r  r4  safe_integerr5  
safe_tradeiso8601)r   r   r	  r  r  r*  r#  r"  r   r  r  r  r  r   feeCosts                  r  parse_tradez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   c                   K   | j                          d{    | j                  |      }|d   | j                  | j                  ||      d}|+d}||}t	        ||      }| j                  |dz        }	|	|d<   |t	        |d      |d<   | j                  | j                  ||             d{   }
| j                  |
dg       }| j                  |||||      S 7 7 .w)	a  
        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
        Nr   )r	  intervalr     startr   rR  )
r\  r	  r4  r   r%  parse_to_intv1PublicGetKliner  r  parse_ohlcvs)r   r  	timeframer  r   r  r	  r  maxLimitr  rP  rR  s               r  fetch_ohlcvzwhitebit.fetch_ohlcv  s      !!!V$Tl(()YO
 H} x(E%%edl3E$GG"5$/GG..t{{7F/KLL (B7  E5II9 	" Ms"   C"CBC"1C 2-C" C"c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   rh              )r  r9  )r   ohlcvr	  s      r  parse_ohlcvzwhitebit.parse_ohlcv3  sn     q)UA&UA&UA&UA&UA&
 	
r  c                    K   | j                  |       d{   }| j                  |d      }|dk(  rdn|ddd|dS 7 %w)aQ  
        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>`
        Nr   pongok)statusupdatedetaurlr3  )v4PublicGetPingr4  )r   r  rP  r  s       r  fetch_statuszwhitebit.fetch_statusH  sV      --f55 !!(A.%/df
 	
 6s   ?=&?c                 d   K   | j                  |       d{   }| j                  |d      S 7 w)aR  
        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
        Nr   )v4PublicGetTimer  )r   r  rP  s      r  
fetch_timezwhitebit.fetch_time`  s5      --f55   622 6s   0.0r  r*  c                 r   K   d|i}| j                  |d|dd| j                  ||             d{   S 7 w)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>`
        r*  r	  r   N)create_orderr  )r   r  r  r*  r  reqs         r  create_market_order_with_costz&whitebit.create_market_order_with_costq  sD      D
 &&vxq$TWY_H`aaaas   .757c                 F   K   | j                  |d||       d{   S 7 w)a  
        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>`
        buyN)r  )r   r  r*  r  s       r  !create_market_buy_order_with_costz*whitebit.create_market_buy_order_with_cost  s%      77tVTTTTs   !!r  r"  r#  c                   K   | j                          d{    | j                  |      }|d   |d}d}	| j                  |d      \  }	}|	8|dk7  s|dk7  rt        | j                  dz         | j                  ||	      |d<   n| j                  ||      |d<   | j                  |d	d
      }
|
5| j                  | j                  d      }|/|| j                         z   |d
<   n|
|d
<   | j                  |d
g      }| j                  |d      }|dk(  }|dk(  }| j                  |g d      }|du}| j                  |d|      }| j                  d|      \  }}|rd|d<   ||dk7  rt        | j                  dz         | j                  |g d      }|duxs |dk(  }d}|r| j!                  ||      |d<   |r@| j!                  ||      |d<   | j#                  | j%                  ||             d{   }nE|r+| j'                  | j%                  ||             d{   }n| j)                  | j%                  ||             d{   }n|rk| j!                  ||      |d<   |r*| j+                  | j%                  ||             d{   }n| j-                  | j%                  ||             d{   }n|r*| j/                  | j%                  ||             d{   }nU|	*| j1                  | j%                  ||             d{   }n)| j3                  | j%                  ||             d{   }| j5                  |      S 7 87 `7 67 7 7 7 {7 Q7 )w)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>`
        Nr   )r	  r  r*  r  r	  z; createOrder() cost is only supported for market buy ordersr"  clOrdIdclientOrderIdr   r  r   r   	stopPriceactivation_priceFrH   TpostOnlycrossz1 createOrder() is only available for cross margin)r  r   r	  r<   r
  r#  )r\  r	  handle_param_stringr*   r   cost_to_precisionamount_to_precisionr  r4  r   uuid16omitsafe_number_nis_post_onlyhandle_margin_mode_and_paramsr,   price_to_precisionv4PrivatePostOrderStopLimitr  )v4PrivatePostOrderCollateralTriggerMarketv4PrivatePostOrderStopMarket!v4PrivatePostOrderCollateralLimitv4PrivatePostOrderNew"v4PrivatePostOrderCollateralMarketv4PrivatePostOrderMarketv4PrivatePostOrderStockMarketparse_order)r   r  r  r  r"  r#  r  r	  r  r*  r  r   
marketTypeisLimitOrderisMarketOrderr   isStopOrderr  r   queryuseCollateralEndpointrP  s                         r  r  zwhitebit.create_order  s    . !!!V$Tl
 //?f48#3"477-j#jkk $ 6 6vt DGH $ 8 8 HGH**69oN ''jAH#+3dkkm+C('4GO$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&'#'#:#:65#I !%!A!A$++gW]B^!__ )%)%S%STXT_T_`gioTp%qqH%)%F%Ft{{SZ\bGc%ddH#'#:#:65#I (%)%K%KDKKX_agLh%iiH%)%?%?GU[@\%]]H )%)%L%LT[[Y`bhMi%jjH')-)F)Ft{{SZ\bGc)d#d)-)K)KDKKX_agLh)i#i))C 	"R `  rd  j]  k $e#is   M$MGM$1M2,M$M*M$	M
AM$M)M$6M7+M$"M#+M$M )M$8M"9M$M$M$M$M$M$M$ M$"M$r   c                 *  K   |t        | j                  dz         |t        | j                  dz         | j                          d{    | j                  |      }||d   d}	| j	                  |dd      }
|
|
|	d<   |dk(  }| j                  |g d	      }|du}| j                  |g d
      }|rs| j                  ||      |	d<   |r+| j                  ||      |	d<   | j                  ||      |	d<   n]|dk(  r| j                  ||      |	d<   nB| j                  ||      |	d<   n,| j                  ||      |	d<   |r| j                  ||      |	d<   | j                  | j                  |	|             d{   }| j                  |      S 7 D7 w)a  
        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>`
        Nz# editOrder() requires a id argumentz' editOrder() requires a symbol argumentr   )r  r	  r  r  r   r  )r  r  r   r	  r
  r"  r#  r  total)r&   r   r\  r	  r  r  r  r  r  v4PrivatePostOrderModifyr  r  )r   r   r  r  r  r"  r#  r  r	  r  r  r   r   r"  rP  s                  r  
edit_orderzwhitebit.edit_order  s     :#DGG.S$STT>#DGG.W$WXX!!!V$Tl
 **69oN$'4GO$w))&2cd#4/6#\]*.*A*A&,*WG&'$($<$<VV$L!#'#:#:65#I  5='+'?'?'OGG$(,(@(@(PGH% $ 8 8 HGH#'#:#:65#I 66t{{7F7STT))C 	"@ Us%   AF
FD-F8F9FFc                 .  K   |t        | j                  dz         | j                          d{    | j                  |      }|d   t	        |      d}| j                  | j                  ||             d{   }| j                  |      S 7 `7 w)a  
        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>`
        Nz) cancelOrder() requires a symbol argumentr   )r	  r  )r&   r   r\  r	  intv4PrivatePostOrderCancelr  r  )r   r   r  r  r	  r  rP  s          r  cancel_orderzwhitebit.cancel_order  s      >#DGG.Y$YZZ!!!V$Tl2w
 66t{{7F7STT( ))5 	" Us"   .BBA
B;B<BBc                 &  K   | j                          d{    d}i }|| j                  |      }|d   |d<   d}| j                  d||      \  }}g }|dk(  r?d}| j                  |ddd      \  }}|r|j	                  d       nG|j	                  d       n5|d	k(  r|j	                  d
       nt        | j                  dz   |z   dz         ||d<   | j                  | j                  ||             d{   }| j                  ||      S 7 7 w)a2  
        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	  r?   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.  rP  s	            r  cancel_all_orderszwhitebit.cancel_all_ordersC  s1     !!![[(F &tGH99:KVU[\f6>H#<<VEVXbdijHf""8,""6*V^y)tww)OORVVY``aa%99$++gv:VWW   6223 	"* Xs"   DDCD6D7DDtimeoutc                   K   | j                          d{    | j                  |d      }|t        | j                  dz         | j	                  |      }| j                  |d      }|dkD  }d|d   i}|r| j                  |dz        |d<   nd	|d<   | j                  | j                  ||             d{   }|S 7 7 w)
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
        Nr  z< cancelAllOrdersAfter() requires a symbol argument in paramsr   r	  r   r  r5  null)	r\  r4  r&   r   r	  r  number_to_stringv4PrivatePostOrderKillSwitchr  )r   r5  r  r  r	  isBiggerThanZeror  rP  s           r  cancel_all_orders_afterz whitebit.cancel_all_orders_afterj  s      !!!!!&(3>#DGG.l$lmmV$68,#aKfTl
 !%!6!6w~!FGI!'GI::4;;wPV;WXX 1 	" Ys"   CC B"C9C:CCc                    t        |j                               }i }t        dt        |            D ]  }||   }| j	                  |      }||   }t        |t              rX|V| j                         }| j                  |dd      |d<   | j                  |d      |d<   | j                  |d      |d<   |||<   | j                         }||d<   |||<    | j                  |      S )Nr   	availablemain_balancefreefreezeusedr&  )rK  rL  rM  rN  r5  r  dictr   r  r4  safe_balance)	r   rP  balanceKeysrR  rS  r   rG  balancer   s	            r  parse_balancezwhitebit.parse_balance  s    8==?+q#k*+ 	'AQB**2.DrlG'4(W-@,,."&"4"4Wk>"Z"&"2"27H"E#'#3#3G^#L &t,,.#* &t	'   ((r  c                   K   | j                          d{    d}| j                  dd|      \  }}d}|dk(  r| j                  |       d{   }n| j                  | j                  di       }| j                  |d      }| j                  |dd|      }| j                  |ddg      }|dk(  s|dk(  r| j                  |       d{   }n| j                  |       d{   }| j                  |      S 7 7 7 37 w)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>`
        NrO   r<   r   r  r   r   )r\  r/  %v4PrivatePostCollateralAccountBalancer6  r   r4  r  r  v4PrivatePostMainAccountBalance v4PrivatePostTradeAccountBalancerF  )r   r  r  rP  r   defaultAccountr   s          r  fetch_balancezwhitebit.fetch_balance  s     !!!
!??PTV\]
F!GGOOHoodllNBGG!--gyAN((FNSGYYv	6':;F& Gy$8!%!E!Ef!MM!%!F!Fv!NN. !!(++K 	"
 P NNsF   DC97DC;A:D	C=
D#C?$D;D=D?Dc                 "  K   | j                          d{    d}i }|| j                  |      }|d   |d<   |t        |d      |d<   | j                  | j	                  ||             d{   }| j                  ||||ddi      S 7 t7 w)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   r  r  )r\  r	  r%  v4PrivatePostOrdersr  r2  r  s           r  fetch_open_orderszwhitebit.fetch_open_orders  s      !!![[(F &tGH"5#GG11$++gv2NOO*   65%(FASTT; 	" Ps"   BBAB/B0BBc           	        K   | j                          d{    i }d}|| j                  |      }|d   }|d   |d<   |t        |d      |d<   | j                  | j	                  ||             d{   }t        |j                               }g }	t        dt        |            D ]q  }
||
   }| j                  |dd      }||   }t        dt        |            D ]:  }| j                  ||   |      }|	j                  | j	                  |d	d
i             < s | j                  |	d      }	| j                  |	|||      }	|	S 7 /7 ӭw)aE  
        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  r  closedr  )r\  r	  r%  %v4PrivatePostTradeAccountOrderHistoryr  rK  rL  rM  rN  r  r  r0  sort_byfilter_by_symbol_since_limit)r   r  r  r   r  r  r	  rP  r  r  rS  r  r  r   jr  s                   r  fetch_closed_orderszwhitebit.fetch_closed_orders  sh     !!![[(FH%F &tGH"5#GGCCDKKPWY_D`aa$ )	q#i.) 	IA |H((4=Ih'F1c&k* I((I>t{{58X2FGHI		I ,,w433GVUERM 	" bs#   E
EAE
4E5CE
E
c                 <    dddddddd}| j                  |||      S )Nr   r	  )r   r	  stop marketz
stop limitzstock marketzmargin limitzmargin marketr4  )r   r  typess      r  parse_order_typezwhitebit.parse_order_type3  s5    #!$#%
 tT22r  r  c                 z   | j                  |d      }| j                  ||d      }|d   }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|dk(  rd }| j                  |d	      }	| j                  |d
      }
| j                  |dd      }| j                  |d      }| j	                  |      }|dk(  rd }| j                  |d      }| j                  |d      }|dk(  r|dk(  s|dk(  r|}| j                  |d      }d }|| j                  |      |d   d}| j                  |dd      }| j                  |d      }| j                  i d|d|d|d|d|d| j                  |      d|dd dd dd d|d	|	d|d|
d|d|d |d ||d d!|      S )"Nr	  r  r  r  	dealStockleftr   r#  r
  r  r   r  r"  	dealMoneyr  rX  dealFeer  r  ctimer  ftimer3  r  lastTradeTimestampr   r  r  r   filled	remaining)r  r*  r   trades)
r4  r  r9  r  r[  r   r  r  
safe_orderr  )r   r  r	  r  r  r  re  rf  r  r#  r   r  r  	orderTyper"  r*  ra  r   r  rd  s                       r  r  zwhitebit.parse_order?  s   P ##E84!!(FC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                 T  K   | j                          d{    dt        |      i}d}|| j                  |      }|d   |d<   |t        |d      |d<   | j	                  | j                  ||             d{   }| j                  |dg       }	| j                  |	|      S 7 7 +w)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>`
        Nr  r   r	  r   r   records)r\  r*  r	  r%  v4PrivatePostTradeAccountOrderr  r  r  )
r   r   r  r  r   r  r  r	  rP  ra  s
             r  fetch_order_tradeszwhitebit.fetch_order_trades  s      !!!s2w
 [[(F &tGH"5#GG<<T[[RX=YZZ( ~~h	26  v..? 	" [s"   B(B$A#B(:B&;*B(&B(rG  c                 &  K   | j                          d{    | j                  |      }d|d   i}d}| j                  |      r| j                  |d      }|t	        | j
                  dz         ||d<   | j                  |d      }|t	        | j
                  dz         ||d<   | j                  |d      }|t	        | j
                  d	z         | j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  |d
      }	| j                  |di       }
| j                  |
d|	      }| j                  |
d      }| j                  |       ||d||dS 7 t7 7 lw)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>`
        Nr   r   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 fiatr  r   addressmemor3  rT  networkrq  tag)r\  rT  is_fiatr4  r&   r   r9  r6  &v4PrivatePostMainAccountFiatDepositUrlr  v4PrivatePostMainAccountAddresscheck_address)r   rG  r  rT  r  rP  ro  r"  rp  r  r   rq  ru  s                r  fetch_deposit_addresszwhitebit.fetch_deposit_address  s     !!!==&htn
 <<''
;H'2v(vww"*GJ%%fh7F~'2u(uvv &GHvz:H'2w(wxx!HHU\^dIeffH!AA$++gW]B^__H6 x///(Ir:""7Is;w/7#
 	
i 	"$ g_s5   FF
C!F8F9)F"F#A(FFFc                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |di       }| j                  ||      S 7 j7 +w)aC  
        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>`
        Nr   r   r   )r\  rT  (v4PrivatePostMainAccountCreateNewAddressr  r  parse_deposit_addressr   rG  r  rT  r  rP  ra  s          r  create_deposit_addresszwhitebit.create_deposit_address  s      !!!==&htn
 FFt{{SZ\bGcdd& ~~h	26))$993 	"
 er  rT  c                 r    || j                  d |      d | j                  |d      | j                  |d      dS )Nrq  rr  rs  )r5  r4  )r   depositAddressrT  s      r  r}  zwhitebit.parse_deposit_address8  sD     #//h?''	B##NF;
 	
r  r   c                   K   | j                          d{    |t        | j                  dz         |dk  s|dkD  rt        | j                  dz         d|i}| j	                  | j                  ||             d{   S 7 m7 w)a  
        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
        Nz/ setLeverage() does not allow to set per symbolrh     z2 setLeverage() leverage should be between 1 and 20r   )r\  r,   r   r'   &v4PrivatePostCollateralAccountLeverager  )r   r   r  r  r  s        r  set_leveragezwhitebit.set_leverageG  s      !!!tww)ZZ[[qLhmTWW'[[\\
 @@WV\A]^^^ 	" _s"   BBA(B?B BBfromAccount	toAccountc                   K   | j                          d{    | j                  |      }| j                  | j                  d      }| j	                  |||      }| j	                  |||      }	| j                  ||      }
|d   |
||	d}| j                  | j                  ||             d{   }| j                  ||      S 7 7 w)ah  
        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>`
        Nr   r   )r   r"  fromto)	r\  rT  r6  r   r4  currency_to_precision v4PrivatePostMainAccountTransferr  parse_transfer)r   rG  r"  r  r  r  rT  r   fromAccountIdtoAccountIdamountStringr  rP  s                r  r   zwhitebit.transfer_  s      !!!==&7GH((kR&&~y)L11$?tn"!	
 >>t{{7TZ?[\\ ""8X66! 	" ]s"   C	CBC	.C/C	C	r   c           
      :    |d d d | j                  d |      d d d d d	S )N)	r3  r   r  r  rT  r"  r  r  r  )r5  )r   r   rT  s      r  r  zwhitebit.parse_transfer~  s6    
 //h?

 
	
r  rq  c                   K   | j                          d{    | j                  |      }|d   | j                  ||      |d}| j                  |d      }|| j	                         }||d<   |||d<   | j                  |      r1| j                  |d      }	|	t        | j                  dz         |	|d<   | j                  | j                  ||             d{   }
| j                  d|i| j                  |
|            S 7 7 *w)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>`
        Nr   )r   r"  rq  rp  rr  ro  z7 withdraw() requires a provider when the ticker is fiat)r\  rT  r  r6  uuid22rv  r&   r    v4PrivatePostMainAccountWithdrawr  parse_transaction)r   rG  r"  rq  ru  r  rT  r  rp  ro  rP  s              r  r   zwhitebit.withdraw  s     !!!==&tn00v>

 ??6:6{{}H&
?!GFO<<vz:H'2k(kll"*GJ>>t{{7TZ?[\\ {{D(+T-C-CHh-WXX3 	"$ ]s"   DDCDD)DDtransactionc                    | j                  d |      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }i d| j                  |d      d| j                  |d	      d
|d| j                  |      d| j                  |d      d|dk(  r|nd d|d|dk(  r|nd d| j	                  |d      d|dk(  rdndd| j                  ||      d| j                  |      dd dd dd dd d| j                  |d      d | j	                  |d      | j                  ||      d|dS )Nrq  	createdAtr   r  r  r   rp  txidtransactionIdr  r  rt  addressFrom1	addressTo2r"  r  rH  
withdrawalrT  r  tagFromru  tagTocommentdescriptionr   r  )internalr   r3  )safe_currencyr4  r  r  r9  r5  parse_transaction_status)r   r  rT  rq  r  rt  r  r  s           r  r  z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
 //
HE
 d33F;
 t
 t
 4
  T!
" t'']C#
$ ((e< 33JI  /
 	
r  r  c                     i ddddddddddd	dd
ddddddddddddddddddd}| j                  |||      S )Nr  pendingr  3r  4canceled56791011121314151617rY  )r   r  statusess      r  r  z!whitebit.parse_transaction_status  s    


 
 	

 
 
 
 
 )
 )
 )
 )
 )
 )
 )
  )!
$ &&99r  c                 L  K   | j                          d{    d}d|ddd}|| j                  |      }|d   |d<   | j                  | j                  ||             d{   }| j	                  |dg       }| j                  |di       }| j                  ||      S 7 7 >w)a  
        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>`
        Nrh  r   )transactionMethodrp  r   offsetr   r   rk  )r\  rT  v4PrivatePostMainAccountHistoryr  r6  r  r  )	r   r   rG  r  rT  r  rP  rk  firsts	            r  fetch_depositzwhitebit.fetch_deposit	  s      !!!!"	
 }}T*H (GH==dkk'SY>Z[[L //(Ir:w2.%%eX66g 	" \s"   B$B AB$#B"$=B$"B$c                 J  K   | j                          d{    d}dddd}|| j                  |      }|d   |d<   |t        |d      |d<   | j                  | j	                  ||             d{   }| j                  |d	g       }| j                  ||||      S 7 7 -w)
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>`
        Nrh  r   r   )r  r   r  r   r   r   rk  )r\  rT  r%  r  r  r  parse_transactions)	r   rG  r  r   r  rT  r  rP  rk  s	            r  fetch_depositszwhitebit.fetch_depositsK	  s      !!!!"

 }}T*H (GH"5#GG==dkk'SY>Z[[L ..9b9&&w%GGg 	" \s"   B#BAB#3B!4,B#!B#c                   K   | j                          d{    i }d}|| j                  |      }|d   |d<   | j                  | j                  ||             d{   }| j	                  ||      }	| j                  |	|||      S 7 r7 ,w)aq  
        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   rG  r  r  r   r  r  r	  rP  interests
             r  fetch_borrow_interestzwhitebit.fetch_borrow_interest	  s      !!![[(F &tGHII$++V]_eJfgg, ..x@228T5%PP; 	" hs"   BB	ABB+BBr3  c                     | j                  |d      }| j                  ||d      }| j                  |d      }||d| j                  |d      d| j                  |d      d|| j	                  |      d		S )
Nr	  r  
modifyDater  unrealizedFundinggXjP?r"  r  )	r3  r  rT  r  interestRateamountBorrowedr   r  r  )r4  safe_symbolr  r9  r  )r   r3  r	  r  r  r  s         r  parse_borrow_interestzwhitebit.parse_borrow_interest	  s    ( ##D(3!!(FC8''l;	((/BC#"..tX>!"Y/

 
	
r  c                    K   | j                          d{    | j                  |      }| j                  |g|       d{   }| j                  ||      S 7 B7 w)ap  
        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>`
        N)r\  r  fetch_funding_ratesr6  )r   r  r  rP  s       r  fetch_funding_ratezwhitebit.fetch_funding_rate	  sY      !!!V$116(FCCx00 	"Cs!   AA+AAAAc                    K   | j                          d{    | j                  |      }| j                  |       d{   }| j                  |dg       }| j	                  ||      S 7 S7 +w)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
        NrR  )r\  r  v4PublicGetFuturesr  parse_funding_rates)r   r   r  rP  ra  s        r  r  zwhitebit.fetch_funding_rates	  so      !!!%%g.0088Z ~~h"5''g66a 	"8s!   A.A*)A. A,*A.,A.c                    | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	i d|d|d|d|d|d	d d
d d|d|	d| j	                  |	      dd dd dd dd dd dd dd S )N	ticker_id	markPrice
indexPricer  funding_ratenext_funding_rate_timestampr3  r  r  r  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )r4  r  r9  r  r  )
r   r   r	  r  r  r  r  r  r  fundingTimes
             r  parse_funding_ratezwhitebit.parse_funding_rate&
  s_   B ##Hk:!!(F3$$X{;	%%h=
''.A&&x@''2OP
H
f
 
 *	

 L
 
 
 ;
 
 t||K8
 t
 #D
 "4
 "4
 '
  &t!
" #
 	
r  c                 n  K   | j                          d{    |t        | j                  dz         | j                  |      }d|d   i}|||d<   |||d<   | j	                  d||      \  }}| j                  |       d{   }| j                  |dg       }| j                  ||||      S 7 7 -w)	ay  
        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>`
        Nz1 fetchFundingHistory() requires a symbol argumentr	  r   	startDater   endDaterk  )r\  r&   r   r	  handle_until_option,v4PrivatePostCollateralAccountFundingHistoryr  parse_funding_histories)	r   r  r  r   r  r	  r  rP  ra  s	            r  fetch_funding_historyzwhitebit.fetch_funding_historyb
  s      !!!>#DGG.a$abbV$fTl
 #(GK $GG229gvNJJ7SS$ ~~h	26++D&%GG? 	" Ts"   B5B1A.B5B3,B53B5c           
          | j                  |d      }| j                  |d      }|| j                  ||d d      d || j                  |      d | j	                  |d      dS )Nr	  r  r<   fundingAmount)r3  r  rG  r  r  r   r"  )r4  r  r  r  r9  )r   r   r	  r  r  s        r  parse_funding_historyzwhitebit.parse_funding_history
  sn     ##Hh7%%h>	&&xvF"Y/&&xA
 	
r  c                     g }t        dt        |            D ](  }||   }|j                  | j                  ||             * | j	                  |d      }| j                  |||      S )Nr   r  )rM  rN  r0  r  rS  r  )	r   	contractsr	  r  r   rR  rS  r   sorteds	            r  r  z whitebit.parse_funding_histories
  sl    q#i.) 	HA |HMM$44XvFG	H fk2))&%??r  c                 ,  K   | j                          d{    i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||             d{   }| j	                  |d      }| j                  ||||      S 7 y7 ,w)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   rk  )r\  rT  r  r  r  r  )	r   rG  r  r   r  r  rT  rP  rk  s	            r  fetch_deposits_withdrawalsz#whitebit.fetch_deposits_withdrawals
  s     ( !!!}}T*H (GH$GG==dkk'SY>Z[[N ..95&&w%GGa 	" \s"   BBAB%B&+BBfromCodetoCodec                 *  K   | j                          d{    | j                  |      }| j                  |      }||| j                  |      dd}| j                  | j	                  ||             d{   }| j                  |||      S 7 x7 w)aD  
        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>`
        Nr  )r  r  r"  	direction)r\  rT  r8  v4PrivatePostConvertEstimater  parse_conversion)	r   r  r  r"  r  fromCurrency
toCurrencyr  rP  s	            r  fetch_convert_quotezwhitebit.fetch_convert_quote
  s      !!!}}X.]]6*
++F3	
 ::4;;wPV;WXX $$X|ZHH+ 	" Ys"   BBA B7B8BBc                   K   | j                          d{    | j                  |      }| j                  |      }d|i}| j                  | j                  ||             d{   }	| j	                  |	||      S 7 f7 w)aq  
        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>`
        Nr  )r\  rT  v4PrivatePostConvertConfirmr  r  )
r   r   r  r  r"  r  r  r  r  rP  s
             r  create_convert_tradezwhitebit.create_convert_trade  s      !!!}}X.]]6*
r
 99$++gv:VWW $$X|ZHH 	" Xs"   BA=AB%A?&B?Bc                   K   | j                          d{    i }|||d<   |(| j                  |dz        }| j                  |      |d<   |||d<   | j                  d||d      \  }}| j	                  | j                  ||             d{   }| j                  |dg       }| j                  ||d	d
||      S 7 7 /w)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>`
        N
fromTickerr  r  r   r  gMbP?rk  r  r  )r\  r  r8  r  v4PrivatePostConvertHistoryr  r  parse_conversions)	r   rG  r  r   r  r  r  rP  rowss	            r  fetch_convert_trade_historyz$whitebit.fetch_convert_trade_history5  s       !!!$(GL!%%edl3E"33E:GFO$GG224&%P99$++gv:VWW0 ~~h	26%%dD.,PUW\]]G 	" Xs"   CB>A9CC .C C
conversionr  r  c                    | j                  |dg       }| j                  |di       }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d|      }	| j	                  |	|      }
| j                  |d|      }| j	                  ||      }||| j                  |      | j                  |d      |
| j                  |dd	      || j                  |d
d      | j                  |d      d d
S )Npathr   r  r  dateexpireAtr   give	finalGivereceivefinalReceiverate)
r3  r  r  r   r  
fromAmountr  toAmountr#  r   )r  r  r4  r  r5  r  safe_number_2r9  )r   r  r  r  r	  r  fromPathtoPathr  fromCoinr  toCoinr  s                r  r  zwhitebit.parse_conversionj  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                 V  K   | j                          d{    | j                  |      }d|d   i}|||d<   |||d<   | j                  d||      \  }}| j                  | j	                  ||             d{   }| j                  |      }| j                  ||||      S 7 7 +w)aD  
        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>`
        Nr	  r   r  r   r  )r\  r	  r  .v4PrivatePostCollateralAccountPositionsHistoryr  parse_positionsrT  )	r   r  r  r   r  r	  r  rP  	positionss	            r  fetch_position_historyzwhitebit.fetch_position_history  s      !!!V$fTl
 #(GK $GG229gvNLLT[[Y`bhMijj0 ((2	00FE5QQG 	" ks"   B)B%A$B);B'<*B)'B)c                    K   | j                          d{    | j                  |      }| j                  |       d{   }| j                  ||      S 7 @7 w)ar  
        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>`
        N)r\  r  r  r  )r   r   r  rP  s       r  fetch_positionszwhitebit.fetch_positions  s[      !!!%%g.II&QQ, ##Hg661 	"Qs!   AA)A AAAc                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |di       }| j                  ||      S 7 j7 +w)a  
        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>`
        Nr  r   r   )r\  r	  r  r  r  parse_position)r   r  r  r	  r  rP  ra  s          r  fetch_positionzwhitebit.fetch_position  s      !!!V$fTl
 II$++V]_eJfgg, ~~h2.""4009 	"
 hr  positionc                    | j                  |d      }| j                  |d      }| j                  |di       }| j                  |di       }| j                  i d|d| j                  |d      d| j	                  ||      d	d d
d d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd dd dd dd dd dd d|| j                  |      | j                  |d      d d | j                  |d      d d d d | j                  |d      | j                  |d      d      S )Nr	  openDatetpslorderDetailr3  r   
positionIdr  notionalr   liquidationPrice
entryPrice	basePriceunrealizedPnlpnlrealizedPnlr   
pnlPercentr  r+  r  r  r  r   r  r  r;   stopLoss
takeProfit)r  lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentager   initialMargininitialMarginPercentager   marginRatior   r   )r4  r  r  safe_positionr  r9  r  )r   r"  r	  r  r  r%  r&  s          r  r   zwhitebit.parse_position$  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                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |dg       }| j                  ||      S 7 j7 +w)a  
        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>`
        Nr   r   r   )r\  rT  "v4PrivatePostMainAccountSmartPlansr  r  parse_borrow_rater~  s          r  fetch_cross_borrow_ratez whitebit.fetch_cross_borrow_rates  s      !!!==&htn
 @@WV\A]^^ ~~h2.%%dH55 	"
 _r  c                     | j                  |d      }| j                  |d      }| j                  ||      | j                  t        j                  |d            | j                  |d      d d |dS )Nr   percentr  duration)rT  r  periodr  r  r3  )r4  r5  r   r0   r8  r  )r   r3  rT  rt  r>  s        r  r;  zwhitebit.parse_borrow_rate  sv     %%dH5
""43//
HE%%g&8&8%&HI''j9
 	
r  c                 `    | j                  | j                  dg       }| j                  ||      S )Nr   )r6  r   rk  )r   rT  r   s      r  rv  zwhitebit.is_fiat  s*    7GL}}X~66r  c                 B    | j                         | j                  d   z
  S )Nr   )millisecondsr   )r   s    r  noncezwhitebit.nonce  s       "T\\2B%CCCr  r   GETc                    | j                  || j                  |            }| j                  |d      }| j                  |d      }	d| j                  ||      z   }
| j                  d   |   |	   |
z   }|	dk(  r|r|d| j                  |      z   z  }|	dk(  r| j                          t        | j                               }| j                  | j                        }d|z   |
z   }| j                  | j                  ||d	|            }| j                  |      }| j                  | j                  |      |t        j                         }d
| j"                  ||d}||||dS )Nr   rh  r  r   r   ?r   z/api/)r  rD  zapplication/json)zContent-TypezX-TXC-APIKEYzX-TXC-PAYLOADzX-TXC-SIGNATURE)r  r  bodyheaders)r  extract_paramsr6  implode_paramsr   	urlencodecheck_required_credentialsstrrD  encodesecretjsonr  string_to_base64hmachashlibsha512apiKey)r   r	  r   r  r  rI  rH  r#  r   accessibilitypathWithParamsr  rD  rP  r  payload	signatures                    r  signzwhitebit.sign  sN   		&$"5"5d";<//#q)Q/t224@@iiw'6GH$sT^^E222I%++-

%E[[-F''1NBG99T[[Wu)MvVWD++D1G		$++g"6OI 2 $!(#,	G fdwOOr  reasonr  r  rI  rH  c
                 .   |dk(  s|dk(  r0t        | j                  dz   t        |      z   dz   |z   dz   |z         |dk(  r't        | j                  dz   t        |      z   dz         |,| j	                  |d      }
| j                  |d      }| j	                  |d      }| j                  |d	      }|
d uxr |
d
k7  xr |d u}|s|| j                  dz   |z   }|}|r|
}nk| j                  |di       }t        |j                               }t        |      }|dkD  r/|d   }| j                  ||g       }t        |      }|dkD  r|d   n|}| j                  | j                  d   ||       | j                  | j                  d   ||       t        |      y )Ni  i  rg  i  z endpoint not foundr  errorsmessagerG  200r   r   r   )r-   r   rN  r#   r4  r6  r  r  rK  rL  rN  throw_exactly_matched_exceptionr   throw_broadly_matched_exception)r   rG  r\  r  r  rI  rH  rP  requestHeadersrequestBodyr  r^  r_  codeNewhasErrorStatusfeedback	errorInfoerrorObject	errorKeyserrorsLengtherrorKeyerrorMessageArrayerrorMessageLengths                          r  handle_errorsz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__W5MtU]^#H--r  )NN)N)NNN)i__name__
__module____qualname__r   r   r"   r   r  rB  r>  r   rX  r   rb  re  rd  r   r  rN  r   r  r  r   r  r   r   r  r   r  r   r  r  rK  r  r  r  r  r   floatr  r   r  r   r   r  r(  r,  r4  r;  r   rF  rL  rO  rV  r[  r  rm  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  r  r	   r  r   r  r  r   r  r  r!  r   r
   r<  r;  boolrv  rD  r[  r*  ro  __classcell__)r   s   @r  r2   r2      s   G# GR *, #+V #+JU
4 U
F U
n -/ n: n` =A 5
' 5
n BFb 6Aw 6ApV#p /1 -[ -^ 68 "1 "1F "1HO4 O O6 Ob 6:" *G7 *G *GX @DB 'BS 'B 'BS\ 'BR <@d[] A AS A Abfglbm A@ 37TX\eg DRC DRs DRRU DRLN Nv N N` 8<$]ajl )J )JC )JWZ )Jquvzq{ )JV
 
4 
* )+ 
0 ') 3S 3" eg b# bY bV[ b XZ Uc U U^c U mqy{ X* X*I X*Y X*X] X*fi X*t fjx|  FH 4*3 4* 4*9 4*I 4*_b 4*ru 4*l 9=R '*S '*# '*R 59 %3c %3N BD $S $L) )& *, /, /,b 59tZ^gi )Uc )U )UTW )Unrsxny )UV 7;\`ik 2 23 2VY 2ptuzp{ 2h
3S 
3[ [v [ [z ?CQUdhqs ,/3 ,/ ,/3 ,/^a ,/\ =? E
 E
> E
N >@ %: %:N %:N
h 
R` 
 ?C2 _3 _ _0 ac 73 7 7C 7TW 7gt 7>
t 
x 
= 
  JNVX &Y3 &Y &Y &Y]h &YP>
T >
X >
Q\ >
@:s :* 8<B >7c >7 >7@ 04$UYbd ?H ?HC ?Hs ?Himnyiz ?HB 7;$]apt} *Q *QC *QWZ *Qjm *Q  EI  JX  EY *QX!
$ !
 !
. !
F <> 1s 1+ 1 <@ :7 :7| :7x:
6 :
[ :
x 9=4^bkm ,H# ,HS ,HX[ ,Hrv  xF  sG ,H\
f 
0@S @X[ @gklzg{ @ <@daenp DHS DH DH[^ DHuy  {F  vG DHL SW_a !I# !Is !IC !Ifp !IF ]aik IS IC I IVY Ipz I8 =Atbfoq 3^c 3^ 3^\_ 3^vz  |F  wG 3^j:
4 :
x :
\d :
pz :
x FJX\eg 0R3 0Rs 0RRU 0Rlpqylz 0Rd 8<B "7W "74PX> "7H 8: &13 &1h &1PMt MV Mx M^ ?A 6# 6_ 6*
 
7 7 7D &eBSW P2!# !s ! !c !TX !`c !r  r2   )7 ccxt.async_support.base.exchanger   ccxt.abstract.whitebitr   rT  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   typingr"   ccxt.base.errorsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   ccxt.base.decimal_to_precisionr/   ccxt.base.preciser0   r2    r  r  <module>r~     s}    6 .  M  M  M  M  M  M  M  M  * 0 - . ' & . ) * ) + 1 4 %|2x |2r  