
    !:hJ                    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    G/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/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                     | j                   d   r| j                          | j                         }| j                  |      S )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   )r   load_time_differencev4PublicGetMarketsparse_markets)r   paramsr   s      r  fetch_marketszwhitebit.fetch_markets  s>     <<12%%'))+0 !!'**r  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                    | j                  |      }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 )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
        r   can_depositTcan_withdraw	providersN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    ))&1D 8==?#q#c(#  	AQB|H -FJ..>4HK/KF**2.D&(2K  %' "-8!  $#
  $//.I#//.I!	F4L 	B r  Ncodesc                    | j                          | j                  |      }t        |j                               }i }i }t	        dt        |            D ]m  }||   }||   }	| j                  |      }
| j                  |	di       }| j                  |d      ||
<   | j                  |	di       }| j                  |d      ||
<   o |||dS )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>`
        r   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 X]]_-q#m,- 	CA$Q'HH%D**84DtZ<H!%!1!1(G!DLoodIr:G $ 0 0' BK	C %"
 	
r  c                 h    | j                          | j                  |      }| j                  ||      S )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>`
        )r\  r]  parse_deposit_withdraw_fees)r   rY  r  rP  s       r  fetch_deposit_withdraw_feesz$whitebit.fetch_deposit_withdraw_fees  s6     	&&v.V //%@@r  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           	         | j                          | j                  |      }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 )
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
        r   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     	))&1$ q#dll+, 	A\\!_F[[(F//(F8,<bAC''[9H''[9H))(E:H))(E:H *""**84**84F6N	  r  r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

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

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r	  r   rR  )r\  r	  v1PublicGetTickerextend	safe_dictparse_ticker)r   r  r  r	  requestrP  r   s          r  fetch_tickerzwhitebit.fetch_ticker  sr     	V$fTl
 ))$++gv*FG$ (B7  00r  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                    | j                          | j                  |      }d}| j                  |dd|      \  }}d}|dk(  r| j                  |      }n| j	                  |      }| j                  |d      }|| j                  ||      S t        |j                               }i }t        dt        |            D ]7  }||   }	| j                  |	      }
| j                  ||	   |
      }|d   }|||<   9 | j                  |d|      S )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>`
        v4PublicGetTickerry   methodNrR  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  s"    	%%g.$66v~xY_`((--f5H--f5H ^^Hh7
!%%j'::)	q#i.) 	$A |H%%h/F&&x'96BFH%F#F6N	$ ++FHgFFr  r   c                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |d      }| j                  |||      S )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
        r	  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224;;w3OP( ''+>	$$XvyAAr  sincec                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||||      S )a  
        get the list of most recent trades for a particular symbol

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

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r	  r   )r\  r	  v4PublicGetTradesMarketr  parse_tradesr   r  r  r   r  r	  r  rP  s           r  fetch_tradeszwhitebit.fetch_tradesR  sd     	V$fTl
 //GV0LM   65%@@r  c                 D   | j                          d}i }|| j                  |      }|d   |d<   | j                  | j                  ||            }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 )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  s-    	[[(F &tGH@@WV\A]^L h%$$XvueDDG(D1c$i( =7 ,,XtSA	 OOHhC	**9iN++GV<= nnWk4@G--gue[QQr  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                    | j                          | j                  |      }|d   | j                  | j                  ||      d}|+d}||}t	        ||      }| j                  |dz        }	|	|d<   |t	        |d      |d<   | j                  | j                  ||            }
| j                  |
dg       }| j                  |||||      S )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
        r   )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((Wf)EF (B7  E5IIr  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                 f    | j                  |      }| j                  |d      }|dk(  rdn|ddd|dS )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>`
        r   pongokN)statusupdatedetaurlr3  )v4PublicGetPingr4  )r   r  rP  r  s       r  fetch_statuszwhitebit.fetch_statusH  sJ     ''/ !!(A.%/df
 	
r  c                 H    | j                  |      }| j                  |d      S )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
        r   )v4PublicGetTimer  )r   r  rP  s      r  
fetch_timezwhitebit.fetch_time`  s)     ''/   622r  r  r*  c                 V    d|i}| j                  |d|dd| j                  ||            S )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  s9     D
   4D$++cSYBZ[[r  c                 *    | j                  |d||      S )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>`
        buy)r   )r   r  r*  r  s       r  !create_market_buy_order_with_costz*whitebit.create_market_buy_order_with_cost  s     11&%vNNr  r  r"  r#  c                    | j                          | 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<   |r8| j!                  ||      |d<   | j#                  | j%                  ||            }n|r"| j'                  | j%                  ||            }n| j)                  | j%                  ||            }n|r[| j!                  ||      |d<   |r"| j+                  | j%                  ||            }n| j-                  | j%                  ||            }ni|r"| j/                  | j%                  ||            }nE|	"| j1                  | j%                  ||            }n!| j3                  | j%                  ||            }| j5                  |      S )a#  
        create a trade order

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

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.cost]: *market orders only* the cost of the order in units of the base currency
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param bool [params.postOnly]: If True, the order will only be posted to the order book and not executed immediately
        :param str [params.clientOrderId]: a unique id for the order
        :param str [params.marginMode]: 'cross' or 'isolated', for margin trading, uses self.options.defaultMarginMode if not passed, defaults to None/None/None
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   )r	  r  Nr*  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 ;;DKKQW<XY )#MMdkkZaciNjkH#@@WV\A]^H#'#:#:65#I (#EEdkkRY[aFbcH#99$++gv:VWH )#FFt{{SZ\bGcdH'#'#@#@WV\A]#^#'#E#EdkkRY[aFb#c))r  r   c                    |t        | j                  dz         |t        | j                  dz         | j                          | 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                  |	|            }| j                  |      S )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 00Wf1MN))r  c                     |t        | j                  dz         | j                          | j                  |      }|d   t	        |      d}| j                  | j                  ||            }| j                  |      S )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>`
        z) 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
 00Wf1MN( ))r  c                    | j                          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                  ||            }| j                  ||      S )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  s    	[[(F &tGH99:KVU[\f6>H#<<VEVXbdijHf""8,""6*V^y)tww)OORVVY``aa%33DKK4PQ   622r  timeoutc                 \   | j                          | j                  |d      }|t        | j                  dz         | j	                  |      }| j                  |d      }|dkD  }d|d   i}|r| j                  |dz        |d<   nd|d<   | j                  | j                  ||            }|S )	a/  
        dead man's switch, cancel all orders after the given timeout

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

        :param number timeout: time in milliseconds, 0 represents cancel the timer
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.types]: Order types value. Example: "spot", "margin", "futures" or None
        :param str [params.symbol]: symbol unified symbol of the market the order was made in
        :returns dict: the api result
        r  z< cancelAllOrdersAfter() requires a symbol argument in paramsr   r	  r   r  r4  null)	r\  r4  r&   r   r	  r  number_to_stringv4PrivatePostOrderKillSwitchr  )r   r4  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4T[[&5QR r  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                    | j                          d}| j                  dd|      \  }}d}|dk(  r| j                  |      }n| j                  | j                  di       }| j                  |d      }| j                  |dd|      }| j                  |ddg      }|dk(  s|dk(  r| j                  |      }n| j                  |      }| j                  |      S )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 v4PrivatePostTradeAccountBalancerE  )r   r  r  rP  r   defaultAccountr   s          r  fetch_balancezwhitebit.fetch_balance  s     	
!??PTV\]
FAA&IHoodllNBGG!--gyAN((FNSGYYv	6':;F& Gy$8??G@@H. !!(++r  c                     | j                          d}i }|| j                  |      }|d   |d<   |t        |d      |d<   | j                  | j	                  ||            }| j                  ||||ddi      S )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  r1  r  s           r  fetch_open_orderszwhitebit.fetch_open_orders  s     	[[(F &tGH"5#GG++DKK,HI*   65%(FASTTr  c           	      f   | j                          i }d}|| j                  |      }|d   }|d   |d<   |t        |d      |d<   | j                  | j	                  ||            }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 )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  r/  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  sM    	[[(FH%F &tGH"5#GG==dkk'SY>Z[$ )	q#i.) 	IA |H((4=Ih'F1c&k* I((I>t{{58X2FGHI		I ,,w433GVUERr  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  rW  dealFeer  r  ctimer  ftimer3  r  lastTradeTimestampr   r
  r  r   filled	remaining)r  r*  r   trades)
r4  r  r9  r  rZ  r   r  r  
safe_orderr  )r   r  r	  r  r  r  rd  re  r  r#  r   r  r  	orderTyper"  r*  r`  r   r  rc  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                 $   | j                          dt        |      i}d}|| j                  |      }|d   |d<   |t        |d      |d<   | j	                  | j                  ||            }| j                  |dg       }	| j                  |	|      S )a,  
        fetch all the trades made from a single order

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

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r  Nr   r	  r   r   records)r\  r)  r	  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66t{{7F7ST( ~~h	26  v..r  rG  c                    | j                          | 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                  ||            }n!| j                  | j                  ||            }| j                  |d
      }	| j                  |di       }
| j                  |
d|	      }| j                  |
d      }| j                  |       ||d||dS )a  
        fetch the deposit address for a currency associated with self account

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

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r   r   NproviderzB fetchDepositAddress() requires a provider when the ticker is fiatr"  zA fetchDepositAddress() requires an amount when the ticker is fiatuniqueIdzC fetchDepositAddress() requires an uniqueId when the ticker is fiatr  r   addressmemor3  rT  networkrp  tag)r\  rT  is_fiatr4  r&   r   r9  r6  &v4PrivatePostMainAccountFiatDepositUrlr  v4PrivatePostMainAccountAddresscheck_address)r   rG  r  rT  r  rP  rn  r"  ro  r  r   rp  rt  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BB4;;wX^C_`H;;DKKQW<XYH6 x///(Ir:""7Is;w/7#
 	
r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )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>`
        r   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  ss     	==&htn
 @@WV\A]^& ~~h	26))$99r  rT  c                 r    || j                  d |      d | j                  |d      | j                  |d      dS )Nrp  rq  rr  )r5  r4  )r   depositAddressrT  s      r  r|  zwhitebit.parse_deposit_address8  sD     #//h?''	B##NF;
 	
r  r   c                     | j                          |t        | j                  dz         |dk  s|dkD  rt        | j                  dz         d|i}| j	                  | j                  ||            S )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
        z/ 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  sx     	tww)ZZ[[qLhmTWW'[[\\
 ::4;;wPV;WXXr  fromAccount	toAccountc                 f   | j                          | j                  |      }| j                  | j                  d      }| j	                  |||      }| j	                  |||      }	| j                  ||      }
|d   |
||	d}| j                  | j                  ||            }| j                  ||      S )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>`
        r   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"!	
 88Wf9UV ""8X66r  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  rp  c                    | j                          | j                  |      }|d   | j                  ||      |d}| j                  |d      }|| j	                         }||d<   |||d<   | j                  |      r1| j                  |d      }	|	t        | j                  dz         |	|d<   | j                  | j                  ||            }
| j                  d|i| j                  |
|            S )a  
        make a withdrawal

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

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r   )r   r"  rp  ro  rq  rn  z7 withdraw() requires a provider when the ticker is fiat)r\  rT  r  r6  uuid22ru  r&   r    v4PrivatePostMainAccountWithdrawr  parse_transaction)r   rG  r"  rp  rt  r  rT  r  ro  rn  rP  s              r  r   zwhitebit.withdraw  s     	==&tn00v>

 ??6:6{{}H&
?!GFO<<vz:H'2k(kll"*GJ88Wf9UV {{D(+T-C-CHh-WXXr  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 )Nrp  	createdAtr   r  r  r   ro  txidtransactionIdr  r  rs  addressFrom1	addressTo2r"  r  rH  
withdrawalrT  r  tagFromrt  tagTocommentdescriptionr   r  )internalr   r3  )safe_currencyr4  r  r  r9  r5  parse_transaction_status)r   r  rT  rp  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17rX  )r   r  statusess      r  r  z!whitebit.parse_transaction_status  s    


 
 	

 
 
 
 
 )
 )
 )
 )
 )
 )
 )
  )!
$ &&99r  c                    | j                          d}d|ddd}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  ||      S )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   )transactionMethodro  r   offsetr   r   rj  )r\  rT  v4PrivatePostMainAccountHistoryr  r6  r  r  )	r   r   rG  r  rT  r  rP  rj  firsts	            r  fetch_depositzwhitebit.fetch_deposit	  s     	!"	
 }}T*H (GH77GV8TUL //(Ir:w2.%%eX66r  c                    | j                          d}dddd}|| j                  |      }|d   |d<   |t        |d      |d<   | j                  | j	                  ||            }| j                  |d	g       }| j                  ||||      S )
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   rj  )r\  rT  r%  r  r  r  parse_transactions)	r   rG  r  r   r  rT  r  rP  rj  s	            r  fetch_depositszwhitebit.fetch_depositsK	  s     	!"

 }}T*H (GH"5#GG77GV8TUL ..9b9&&w%GGr  c                     | j                          i }d}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  ||      }	| j                  |	|||      S )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CCDKKPWY_D`a, ..x@228T5%PPr  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                     | j                          | j                  |      }| j                  |g|      }| j                  ||      S )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>`
        )r\  r  fetch_funding_ratesr6  )r   r  r  rP  s       r  fetch_funding_ratezwhitebit.fetch_funding_rate	  sC     	V$++VHf=x00r  c                     | j                          | j                  |      }| j                  |      }| j                  |dg       }| j	                  ||      S )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
        rR  )r\  r  v4PublicGetFuturesr  parse_funding_rates)r   r   r  rP  ra  s        r  r  zwhitebit.fetch_funding_rates	  sX     	%%g.**62Z ~~h"5''g66r  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                 >   | j                          |t        | j                  dz         | j                  |      }d|d   i}|||d<   |||d<   | j	                  d||      \  }}| j                  |      }| j                  |dg       }| j                  ||||      S )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>`
        z1 fetchFundingHistory() requires a symbol argumentr	  r   	startDater   endDaterj  )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DDWM$ ~~h	26++D&%GGr  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  r/  r  rR  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                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |d      }| j                  ||||      S )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   rj  )r\  rT  r  r  r  r  )	r   rG  r  r   r  r  rT  rP  rj  s	            r  fetch_deposits_withdrawalsz#whitebit.fetch_deposits_withdrawals
  s    ( 	}}T*H (GH$GG77GV8TUN ..95&&w%GGr  fromCodetoCodec                     | j                          | j                  |      }| j                  |      }||| j                  |      dd}| j                  | j	                  ||            }| j                  |||      S )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>`
        r  )r  r  r"  	direction)r\  rT  r7  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4T[[&5QR $$X|ZHHr  c                     | j                          | j                  |      }| j                  |      }d|i}| j                  | j                  ||            }	| j	                  |	||      S )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>`
        r  )r\  rT  v4PrivatePostConvertConfirmr  r  )
r   r   r  r  r"  r  r  r  r  rP  s
             r  create_convert_tradezwhitebit.create_convert_trade  sl     	}}X.]]6*
r
 33DKK4PQ $$X|ZHHr  c                 X   | j                          i }|||d<   |(| j                  |dz        }| j                  |      |d<   |||d<   | j                  d||d      \  }}| j	                  | j                  ||            }| j                  |dg       }| j                  ||dd	||      S )
a]  
        fetch the users history of conversion trades

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

        :param str [code]: the unified currency code
        :param int [since]: the earliest time in ms to fetch conversions for
        :param int [limit]: the maximum number of conversion structures to retrieve, default 20, max 200
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.until]: the end time in ms
        :param str [params.fromTicker]: the currency that you sold and converted from
        :param str [params.toTicker]: the currency that you bought and converted into
        :param str [params.quoteId]: the quote id of the conversion
        :returns dict[]: a list of `conversion structures <https://docs.ccxt.com/#/?id=conversion-structure>`
        
fromTickerr  r  r   r  gMbP?rj  r  r  )r\  r  r7  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33DKK4PQ0 ~~h	26%%dD.,PUW\]]r  
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                 &   | j                          | j                  |      }d|d   i}|||d<   |||d<   | j                  d||      \  }}| j                  | j	                  ||            }| j                  |      }| j                  ||||      S )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>`
        r	  r   r  r   r  )r\  r	  r  .v4PrivatePostCollateralAccountPositionsHistoryr  parse_positionsrS  )	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FFt{{SZ\bGcd0 ((2	00FE5QQr  c                     | j                          | j                  |      }| j                  |      }| j                  ||      S )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>`
        )r\  r  r  r  )r   r   r  rP  s       r  fetch_positionszwhitebit.fetch_positions  sE     	%%g.CCFK, ##Hg66r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )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>`
        r  r   r   )r\  r	  r  r  r  parse_position)r   r  r  r	  r  rP  ra  s          r  fetch_positionzwhitebit.fetch_position  st     	V$fTl
 CCDKKPWY_D`a, ~~h2.""400r  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                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  ||      S )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>`
        r   r   r   )r\  rT  "v4PrivatePostMainAccountSmartPlansr  r  parse_borrow_rater}  s          r  fetch_cross_borrow_ratez whitebit.fetch_cross_borrow_rates  ss     	==&htn
 ::4;;wPV;WX ~~h2.%%dH55r  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  ru  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  rC  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strrC  encodesecretjsonr  string_to_base64hmachashlibsha512apiKey)r   r  r   r  r  rH  rG  r"  r   accessibilitypathWithParamsr  rC  rO  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  rH  rG  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   rM  r#   r4  r6  r  r  rK  rL  rN  throw_exactly_matched_exceptionr   throw_broadly_matched_exception)r   rG  r[  r  r  rH  rG  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  rA  r>  r   rX  r   rb  re  rd  r   r  rM  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+  r3  r:  r   rE  rK  rN  rU  rZ  r  rl  r   ry  r~  r   r|  r  r!   r   r  r    r   r  r  r  r  r   r  r  r   r  r   r  r  r   r  r  r  r  r	   r  r  r  r  r   r  r  r   r  r
   r;  r:  boolru  rC  rZ  r)  rn  __classcell__)r   s   @r  r2   r2      s   G# GR $& #+$v, #+JU
4 U
F U
n ') nZ n` 7;2 5
G 5
n <@ 6A 6ApV#p )+ -{ -^ 02 "13 "1f "1HO4 O O6 Ob 04B *GW *G7 *GX :>b 'Bs 'B3 'BY 'BR 6:UW A3 As A# A\`af\g A@ -1tRV_a DRc DR DRC DRLN Nv N N` 26DW[df )J# )Jc )JQT )Jkoptku )JV
 
4 
* #% 
0 !# 3s 3" _a \C \y \PU \ RT O O5 OX] O gksu X*3 X*i X*y X*RW X*`c X*t `drv  @B 4*S 4*# 4*Y 4*i 4*Y\ 4*lo 4*l 37r '*s '*C '*R /32 %3 %3N <> $s $L) )& $& /,( /,b /3TXac )U )U3 )Uc )Uhlmrhs )UV 154VZce 2# 2S 2PS 2jnotju 2h
3S 
3[ [v [ [z 9=4^bkm ,/S ,/# ,/S ,/X[ ,/\ 79 E
# E
^ E
N 8: %:3 %:n %:N
h 
R` 
 9=R YS Y# Y0 [] 7S 7% 7c 7c 7an 7>
t 
x 
= 
  DHPR &YS &Y% &Y# &YWb &YP>
T >
X >
Q\ >
@:s :* 26b >7 >73 >7@ *.Dt\^ ?H3 ?Hc ?H ?Hcghsct ?HB 15DW[jnwy *Q# *Qc *QQT *Qdg *Q  C  DR  S *QX!
$ !
 !
. !
F 68 1 1K 1 6:" :77 :7 :7x:
6 :
[ :
x 37TX\eg ,HC ,Hs ,HRU ,Hlpq  mA ,H\
f 
0@S @X[ @gklzg{ @ 6:[_hj DHs DH# DHUX DHost  pA DHL MQY[ !IC !I !Ic !I`j !IF W[ce Is Ic I3 IPS Ijt I8 7;\`ik 3^ 3^3 3^VY 3^ptu  qA 3^j:
4 :
x :
\d :
pz :
x @DRV_a 0RS 0R 0RC 0Rfjksft 0Rd 26b "7w "7T(^ "7H 24 &1S &1 &1PMt MV Mx M^ 9; 6C 6 6*
 
7 7 7D &eBSW P2!# !s ! !c !TX !`c !r  r2   )7ccxt.base.exchanger   ccxt.abstract.whitebitr   rS  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}    ( .  M  M  M  M  M  M  M  M  * 0 - . ' & . ) * ) + 1 4 %|2x |2r  