
    !:ho                       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l%m2Z2 d dl%m3Z3 d dl4m5Z5 d dl6m7Z7  G d dee      Z8y)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntLeverage
MarginModeMarginModesMarginModificationMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRates
OrderBooksTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)	TICK_SIZE)Precisec                   H    e Zd Zdef fdZd Zi fdee   fdZi fde	fdZ
i fdedefdZi fdedefdZdefd	Zi fdefd
Zi fdedefdZdi fdedefdZdld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dldededefdZd ZdefdZ d Z!dld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%d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dee#   fd"Z'ddi fdedede(fd#Z)di fdedede*fd$Z+dld%edede,fd&Z-i fdede,fd'Z.i fde/fd(Z0d)ddi fdedededee1   fd*Z2dldede1fd+Z3dddi fdedededee4   fd,Z5di fd-edefd.Z6dddi fd-edededefd/Z7dddi fdedededee4   fd0Z8di fd-edefd1Z9di fdefd2Z:di fd-edefd3Z;ddi fd-eded4e<d5e=d6e>d7e>fd8Z?di fded4e<d5e=d6e@d7e>f
d9ZAddi fdeBd:ed4e<d5e=d6e@d7e>d;efd<ZCdefd=ZDdld>edede4fd?ZEdi fdee   deFfd@ZGdld;edeHfdAZIi fded6e@dBedCedeJf
dDZKdldEede"deJfdFZLdefdGZMdi fded6e@dHede#fdIZNdi fdedeOfdJZPdddi fdededefdKZQdi fdedeeR   fdLZSi fdefdMZTdldNedefdOZUdldefdPZVdi fdefdQZWi fdefdRZXi fdedeYfdSZZdldedeYfdTZ[i fdede\fdUZ]dldVedede\fdWZ^i fded6e@de\fdXZ_i fded6e@de\fdYZ`i fdedeafdZZbdld[ededeafd\Zcdi fd[edefd]Zddi fd^efd_Zedlde"fd`Zfdi fded5e=de4fdaZgi df fdb	ZhdeidceddedeedfedgefdhZjdidji ddfdkZk xZlS )mhitbtcreturnc                    | j                  t        t        |          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	i dMddNd	dOd	dPd	dQd	dRd	dSd(dTddUd	dVd	dWd	dXd	dYddZdd[dd\d	d]d	t        d^d_d_d`dadad`dbdcdddegdfdggdhdii djdkdldkdmdkdndkdodkdpdkdqdkdrdkdsdkdtdkdudkdvdkdwdkdxdkdydkdzdkd{dkdkdkdkdkdkdkdkdkdkdkdkdkdkd|ii d}d~dd~dddddd~dd~dd~dd~dddddddddddd~dd~dd~dd~i dd~dd~dd~dddddddddd~dd~dd~dd~dd~dd~dd~ddddddddddddddd~d~d~d~di dddddddddddddddddddddddddddddd~dd~dd~dd~idddddddddddddddddddddd`dd	d	| j                  d      | j                  d      | j                  d      | j                  d      g| j                  d      | j                  d      g| j                  d      | j                  d      g| j                  d      | j                  d      g| j                  d      | j                  d      g| j                  d      | j                  d      g| j                  d«      | j                  dë      g| j                  dī      | j                  d      g| j                  dū      | j                  dƫ      g| j                  dǫ      | j                  dƫ      gg
| j                  d      | j                  d      g| j                  d      | j                  dȫ      g| j                  d      | j                  d      g| j                  d      | j                  d      g| j                  d      | j                  d      g| j                  d      | j                  d      g| j                  d«      | j                  d      g| j                  dī      | j                  dɫ      g| j                  dū      | j                  d      g| j                  dǫ      | j                  d      g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	ddddd	dМd	dddd	dќd	ddddd	dҜd d	dddddddd	dӜ	ddid՜	ddiddd	iddiddiddiddidٜddiddidۜddiddidۜdܜddddddddddd
i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt         dt        d t        dt        dt        dt        dt        dt        dt"        dt        dt        i d	t        d
t        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        t        t        t        t        t        di 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/d0d0d1d1i d2d3d4d5d6d7d8d9d:d:d;d;d<d<d=d=d>d>d?d@dAdAdBdBdCdCdDdDdEdEdFdFdGdGi dHdHdIdIdJdJdKdKdLdLdMdMdNdNdOdOdPdPdQdQdRdRdSdTdUdVdWdWdXdXdYdZd[d[i d\d\d]d]d^d^d_d_d`d`dadbdcdcdddedfdfdgdgdhdidjdjdkdkdldldmdmdndndodpi dqdqdrdrdsdsdtdtdududvdvdwdwdxdydzdzd{d|d}d}d~d~ddddddddddddidddddddi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ddddd      S (  Nr4   HitBTCHKgDl
@3CORSFspotTmarginswapfutureoption	addMargincancelAllOrderscancelOrderclosePositioncreateDepositAddresscreateOrdercreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrder	editOrderfetchAccountsfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionsfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchVolatilityHistoryfetchWithdrawalsreduceMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModetransferwithdrawzchttps://user-images.githubusercontent.com/1294454/27766555-8eaec20e-5edc-11e7-9c5b-6dc69fc42f5e.jpgz!https://api.demo.hitbtc.com/api/3)publicprivatezhttps://api.hitbtc.com/api/3zhttps://hitbtc.comz(https://hitbtc.com/?ref_id=5a5d39a65d466zhttps://api.hitbtc.comz=https://github.com/hitbtc-com/hitbtc-api/blob/master/APIv2.mdz"https://hitbtc.com/fees-and-limitszIhttps://support.hitbtc.com/hc/en-us/articles/115005148605-Fees-and-limits)logotestapiwwwreferraldocfeesgetzpublic/currency
   zpublic/currency/{currency}zpublic/symbolzpublic/symbol/{symbol}zpublic/tickerzpublic/ticker/{symbol}zpublic/price/ratezpublic/price/historyzpublic/price/tickerzpublic/price/ticker/{symbol}zpublic/tradeszpublic/trades/{symbol}zpublic/orderbookzpublic/orderbook/{symbol}zpublic/candleszpublic/candles/{symbol}zpublic/converted/candles)z!public/converted/candles/{symbol}zpublic/futures/infozpublic/futures/info/{symbol}zpublic/futures/history/fundingz'public/futures/history/funding/{symbol}z"public/futures/candles/index_pricez+public/futures/candles/index_price/{symbol}z!public/futures/candles/mark_pricez*public/futures/candles/mark_price/{symbol}z$public/futures/candles/premium_indexz-public/futures/candles/premium_index/{symbol}z$public/futures/candles/open_interestz-public/futures/candles/open_interest/{symbol}zspot/balance   zspot/balance/{currency}
spot/order   spot/order/{client_order_id}zspot/feezspot/fee/{symbol}zspot/history/orderzspot/history/tradezmargin/account margin/account/isolated/{symbol}zmargin/account/cross/{currency}margin/ordermargin/order/{client_order_id}zmargin/configzmargin/history/orderzmargin/history/tradezmargin/history/positionszmargin/history/clearingzfutures/balancezfutures/balance/{currency}zfutures/account!futures/account/isolated/{symbol}futures/orderfutures/order/{client_order_id}zfutures/configzfutures/feezfutures/fee/{symbol}zfutures/history/orderzfutures/history/tradezfutures/history/positionszfutures/history/clearingzwallet/balance   zwallet/balance/{currency}zwallet/crypto/address)z$wallet/crypto/address/recent-depositz%wallet/crypto/address/recent-withdrawz wallet/crypto/address/check-minezwallet/transactionszwallet/transactions/{tx_id}zwallet/crypto/fee/estimatezwallet/airdropszwallet/amount-lockszsub-accountsub-account/aclzsub-account/balance/{subAccID}z0sub-account/crypto/address/{subAccID}/{currency}zspot/order/listzmargin/order/listzfutures/order/listzwallet/crypto/withdrawzwallet/convertzwallet/transferzwallet/internal/withdrawz&wallet/crypto/check-offchain-availablezwallet/crypto/fees/estimatezwallet/airdrops/{id}/claimzsub-account/freezezsub-account/activatezsub-account/transferr   )r   r   r   )r   r   zmargin/positionz!margin/position/isolated/{symbol}r   r   zfutures/positionz'futures/position/{margin_mode}/{symbol}r   r   wallet/crypto/withdraw/{id})r   r   r   )r   postpatchdeleteputtradingz0.0009010z0.0007100z0.0006500z0.00051000z0.00035000z0.000210000z0.00012000050000z-0.0001100000z0.0008z0.0004)makertaker)	tierBased
percentager   r   tiers)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingleveragemarketBuyByCostmarketBuyRequiresPriceiceberg  i )r   limitdaysBack	untilDayssymbolRequired
marketType)r   triggerr   r   r   )r   r   r   r   r   r   )	r   r   r   daysBackCanceledr   r   r   r   r   r   )	r   rE   createOrdersrn   rw   rt   rz   rP   ro   extendsdefaultr   )r   rE   rw   rn   rt   rP   forDerivatives)linearinverse)r   r;   r   r=   r>   M1M3M5M15M30H1H4D1D71M)
1m3m5m15m30m1h4h1d1wr   42950350460080010021003100410052001200220032010201120122020202220241000110021100222000120002200032000420005200062000720008200092001020011200122001420016200182003120032200332003420040200412004220043200442004520047200482004920080)2100121003210042200422008)exactbroadERC20ETHTRC20)r*  USDTBTCbtcOMNIethETCBEP20BSCTRXNEARDGBAEARADACHZABBCALGOAPTATOMAVAXCAVACAVAXXAVAXBSVBCHSVBEP2BNBCELOCKBCTXCDASHDCRDOGEdogeEGLDEOSETHWEVERFETFILFLOWGLMRGRINHBARHIVEHYDRAICPICXIOSTIOTAIOTXKAVAKLAYKIMKOMODOKMDKSMLSKLTCltcMINAMOVRNANONEOONEONTOPTIMISMOPPLCUMATICPOLYGONQTUMREIOASISROSERVNSCSCRTSOLSTEEMTHETAThetaTRUEVETVSYSWAVESWAXXCHXECNEMXEMXLMXMRxmrXRDXRPXTZXVGXYMZECZENZILwalletderivatives)r;   fundingr=   r>   
includeFee)defaultNetworkdefaultNetworksnetworksaccountsByTyper   AUTOCubeBCCBDPBidiPassBETz
DAO.CasinoBIT
BitRewardsBOXz	BOX TokenCPTCryptaurGETThemisGMTz	GMT TokenHSRHCIQzIQ.CashLNC
LinkerCoinPLAPlayChipPNTPentaSBTCzSuper BitcoinSTEPNSTXSTOX
TokenvilleMTL)TVXMTXPNT)idname	countries	rateLimitversionhasprecisionModeurlsr   r   features
timeframes
exceptionsoptionscommonCurrencies)deep_extendsuperr4   describer1   parse_numberr.   r#   r/   r%   r$   r)   r(   r+   r&   r*   r,   r0   )self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/hitbtc.pyr  zhitbtc.describe   s1   fd < > VVV $V 	V
 %V %V TV "4V tV  V 'V tV &tV (V 'V  (!V" "4#V$ T%V&  'V( )V* +D+V, )$-V. $T/V0 '1V2 (3V4 "45V6 &t7V8 (9V: 1%;V<  =V> +D?V@ *:AVB +DCVD &tEVF #DGVH *4IVJ $TKVL uMVN "4OVP *5QVR +ESVT  UVV %dWVX $UYVZ ":[V\ #D]V^ +E_V` aVb !$cVd &ueVf +EgVh  iVj dkVl $TmVn +EoVp %dqVr !$sVt "4uVv uwVx #EyVz d{V| !$}V~ "4V@ uAVB #DCVD  EVF !$GVH )$IVJ )%KVL tMVN OVP tQVR "4SVT #DUVV $ZWVX )%YVZ #D[V\ ]V^ 4_V` taVb UcVd  eVf "5gVh DiVj DkVn '}AB
 == ,F,S
 9_!.  )24b ( 1"	
 ( 1" ,R / .r 7 ( 1" +B 4R )"  22!" 3B#$ >@/18::<CE>@GI=?FH@BIK@BIK=!F/&/12/ %a/ 7	/
 #B/ ,R/ -b/ -b/ )!/ ;A/ :1/ '/ 9!/ (/ //  /!/" 3B#/$ 22%/& *2'/( 5b)/* *1+/, <Q-/. (//0 :11/2 )"3/4 &r5/6 /7/8 09/: 0;/< 4R=/> 3B?/@ )"A/B 4RC/D 0E/F ACAC<>/17968+-/1')+-:<LN]/`$a)1 ' ,Q	
 ( -a 0 1" )" *2 3B A" 6r 5b -b  /!" /#$ *2%* 9::;;< '(89+,=>():;,-CD)*;<79 =>=>79o\G@D !%"&!..x8!..x8 "..s3T5F5Fx5PQ!..t4d6G6G6QR!..u5t7H7H7RS!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..w79J9J89TU!..w79J9J39OP!..w79J9J99UV!..x8$:K:KI:VW" "..s3T5F5Fx5PQ!..t4d6G6G6QR!..u5t7H7H7RS!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..w79J9J89TU!..w79J9J89TU!..w79J9J89TU!..x8$:K:KH:UV"!H  $&+(,,0,1).+06:#'#'"&#'	( #(/4$)$)+027#')$, %)&*!%$*%+*/&*& '+#($)*/&*# '+!%#($)*/&*( $(&*!%$*,-%+#($)*/&*
*  #y?B y  )$d$ %e# %e& %e( %e*#( "#3 "#3 	 "#3 "#3 	}fP 9,9=9 /9 /	9
 +9 =9 /9 ,9 /9 /9 I9 J9 J9 J9 J9  J!9" J#9$ J%9& L'9( Z)9* -+9, Z-9. ./90 ]192 ]394 ]596 ]798 ]99: ];9< \=9> \?9@ ]A9B ]C9D ]E9F ]G9H ]I9J ]K9L ]M9N ]O9P ]Q9R ]S9T ]U9V ]W9X ]Y9Z ][9\ -]9^ \_9` \a9b \c9d \e9f ]g9h +--**q9t w<| #* #$y5y Ey 5	y
 Uy 5y Uy Uy Fy 5y $y$ $%y( 5)y2 53y8 F9yB FCyH 5IyR FSyT VUyV VWyb 7cyd EeyB FCyH 5IyT FUy\ F]y` 5ayh Fiyv Fwy@ 5AyD FEyL FMyR 5SyT 5UyX FYyf Fgyl Fmyn Foyr Fsyz W{y| 5}y~ 5yB FCyD FEyF FGyJ FKyL EMyN eOyR 5SyX 5Yy\ 5]yh Fiyn Foyt Fuyx 5yyJ 5KyN 5OyP QyZ F[y` Yayl Fmyp 5qyv Vwy| 5}y@ $AyB FCyL 5MyR WSyZ W[yb Fcyl 5myr Fsyv Wwyx 5yy@ 5AyJ 5KyL 5MyR 5SyV 5Wy` 5ayb 5cyd 5eyf 5gyh 5iyj 5kyl 5myn 5oyv #')+	# !%MIT!!u! z! |	!
 |! {! z! x! {! t! i! |! z! w! !  !!" v#!$ #)!giA
 i i	    c                 "    | j                         S N)milliseconds)r  s    r  noncezhitbtc.nonce  s      ""r  c                 D   | j                  |      }g }t        |j                               }t        dt	        |            D ]Z  }||   }|j                  d      r| j                  ||      }| j                  |d      }| j                  |d      }	|dk(  }
|dk(  }| j                  |dd      }|xr |}|	d	u}|
xr | }d}| j                  |d
d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |      }d	}d	}|dz   |z   }d}d	}d	}d	}|
rI| j                  d      }|}| j                  |      }|d	uxr ||k(  }| }|dz   |z   }|r|dz   |	z   }d}nd}| j                  |d      }| j                  |d      }| j                  |      } | j                  |      }!|j                  i d|d|d|d|d|d|d|d|d|d|d|d|d|d|d d!d"|
d#||| j                  |d$      | j                  |d%      ||	d	d	d	|| |!d&| j                  d      | j                  |d'd(      d)| d	d)|!d	d)| j                  t        j                   ||            d	d)d*d	|d+       ] |S ),z
        retrieves data on all markets for hitbtc

        https://api.hitbtc.com/#symbols

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   _BQXtypeexpiryfuturesr;   margin_tradingFNbase_currency
underlyingquote_currencyfee_currency/1:-r>   r=   quantity_increment	tick_sizer  symbolbasequotesettlebaseIdquoteIdsettleIdr<   r?   activeTcontractr   	take_rate	make_rate)amountpricemax_initial_leverager   minmax)r   r  r  cost)r   r   r   contractSizer  expiryDatetimestrike
optionTypefeeCurrency	precisionlimitscreatedinfo)publicGetPublicSymbollistkeysrangelenendswith
safe_valuesafe_stringsafe_integer	safe_boolsafe_string_2safe_currency_coder  appendsafe_numberr2   
string_mul)"r  paramsresponseresultidsir  marketr   r  r  r;   marginTradingr<   r>   r=   r?   r  r  feeCurrencyIdr  r  r  r  r  r  r  r  r   r   	lotString
stepStringlotsteps"                                     r  fetch_marketszhitbtc.fetch_markets  s    --f5> 8==?#q#c(# ^	AQB{{6"__Xr2F))&&9J&&vx8F"i/H&(D NN63CUKM+mFD(F+VDF''NF&&v/?@G ,,V^DM**62D++G4E11-@KHFCZ%'FDLFG#005(00: ,C5F?$*#.#c\F2F#D!D((1EFI))&+>J##I.C$$Z0DMM 3b3&3 3 	3
 &3 &3 73 H3 3 3 &3 3 &3 &3 $3  H!3" &#3$ #))&+>))&+> , "&"*!!  $005#//8NPQR!
  ##
  $#
  $001C1CIz1Z[#$  e3 3W^	~ r  c                 :   | j                  |      }i }t        |j                               }t        dt	        |            D ]U  }||   }| j                  |      }||   }| j                  |dg       }	i }
t        dt	        |	            D ]  }|	|   }| j                  |dd      }| j                  |      }||j                         n|}|||d| j                  |d      | j                  |d      | j                  |d      | j                  |d	      d
dddid	|
|<    | j                  |||| j                  |d      | j                  |d      | j                  |d       | j                  |d      | j                  |d      |
dddddidd      ||<   X |S )a  
        fetches all available currencies on an exchange

        https://api.hitbtc.com/#currencies

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   r  protocolnetworkN
payout_feepayin_enabledpayout_enabledprecision_payoutr   r  )	r  r  r  r  feedepositr   r  r  precision_transfer	full_namedelistedr  )r  coder  r  r  r  r"  r   r  r!  r  r  )publicGetPublicCurrencyr  r   r  r  r	  	safe_listr  network_id_to_codeupperr  r  safe_currency_structurer  )r  r  r  r  
currenciesr  
currencyIdr&  entryrawNetworksr  j
rawNetwork	networkIdnetworkCodes                  r  fetch_currencieszhitbtc.fetch_currencies  s    //7V (--/*
q#j/* -	A#AJ**:6DZ(E..
B?KH1c+./ (^
 ..z:yQ	"55i@6A6Mk//1TX&#*"++JE#~~j/J $z;K L!%!1!1*>P!Q"#'#'%)%*  77 !--e5IJ((<"nnUJ??>>%A NN52BC$## #9 F4L7-	\ r  r&  c                    | j                          | j                  |      }d|d   i}| j                  |d      }|L|dk(  rG| j                  | j                  d      }| j                  ||      }|||d<   | j                  |d      }| j                  | j                  ||            }| j                  |d      }	| j                  |	      | j                  |d      | j                  |d      d|d	S )
a  
        create a currency deposit address

        https://api.hitbtc.com/#generate-deposit-crypto-address

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        currencyr  r  Nr,  r  address
payment_id)r6  r7  tagr  r  )
load_marketsr6  safe_string_upperr  r  r  omitprivatePostWalletCryptoAddressextendr	  )
r  r&  r  r6  requestr  r  parsedNetworkr  r-  s
             r  create_deposit_addresszhitbtc.create_deposit_address  s    	==&
 ((;dfnt||Z@H ,,Xw?M(&3
#YYvy1F66t{{7F7ST %%h
;
//
;'')<##Hl;
 	
r  c                    | j                          | j                  |      }d|d   i}| j                  |d      }|L|dk(  rG| j                  | j                  d      }| j                  ||      }|||d<   | j                  |d      }| j                  | j                  ||            }| j                  |d      }	| j                  |	d      }
| j                  |	d      }| j                  |	d	      }| j                  |      }||d|
|d
S )av  
        fetch the deposit address for a currency associated with self account

        https://api.hitbtc.com/#get-deposit-crypto-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>`
        r6  r  r  Nr,  r  r   r7  r8  )r  r6  r  r7  r9  )
r:  r6  r;  r  r  r  r<  privateGetWalletCryptoAddressr>  r	  )r  r&  r  r6  r?  r  r  r@  r  firstAddressr7  r-  r9  
parsedCodes                 r  fetch_deposit_addresszhitbtc.fetch_deposit_address"  s     	==&
 ((;dfnt||Z@H ,,Xw?M(&3
#YYvy1F55dkk'66RS x3""<;%%lJ?
|\:,,Z8
"
 	
r  c                 .   d|i}t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )Nr  r   r6  	availablefreereservedused)r  r  r  r	  accountsafe_balance)r  r  r  r  r.  r-  r&  rL  s           r  parse_balancezhitbtc.parse_balanceI  s    )q#h-( 	#AQKE))%<J**:6DllnG"..ukBGFO"..ujAGFO"F4L	#   ((r  c                    | j                  |dd      }| j                  |dg      }| j                  | j                  di       }| j	                  |||      }d}|dk(  r| j                  |      }nq|dk(  r| j                  |      }nZ|dk(  r| j                  |      }nCt        |j                               }t        | j                  dz   dj                  |      z         | j                  |      S )	a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://api.hitbtc.com/#wallet-balance
        https://api.hitbtc.com/#get-spot-trading-balance
        https://api.hitbtc.com/#get-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>`
        r  r;   r  Nr  r  z. fetchBalance() type parameter must be one of , )safe_string_lowerr<  r  r  r  privateGetWalletBalanceprivateGetSpotBalanceprivateGetFuturesBalancer  r   r(   r  joinrN  )r  r  r  r  rL  r  r   s          r  fetch_balancezhitbtc.fetch_balanceU  s     %%fff=6F8,7GL"">4>h33F;H11&9H%44V<H++-.DTWW'WWZ^ZcZcdhZiijj !!(++r  r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://api.hitbtc.com/#tickers

        :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  )r:  r  publicGetPublicTickerSymbolr>  parse_tickerr  r  r  r  r?  r  s         r  fetch_tickerzhitbtc.fetch_ticker{  s`     	V$fTl
 33DKK4PQ   622r  Nsymbolsc                    | j                          | j                  |      }i }|'| j                  |      }dj                  |      }||d<   | j	                  | j                  ||            }i }t        |j                               }t        dt        |            D ]7  }	||	   }
| j                  |
      }|d   }||
   }| j                  ||      ||<   9 | j                  |d|      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://api.hitbtc.com/#tickers

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        ,r\  r   r  )r:  market_symbols
market_idsrU  publicGetPublicTickerr>  r  r   r  r  safe_marketrY  filter_by_array_tickers)r  r\  r  r?  	marketIds	delimitedr  r  r   r  marketIdr  r  r.  s                 r  fetch_tickerszhitbtc.fetch_tickers  s     	%%g.0I+I!*GI--dkk'6.JK  HMMO$q#d)$ 	>AAwH%%h/FH%FX&E!..uf=F6N	> ++FHgFFr  tickerr  c                    | j                  |d         }| j                  d |      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  i d|d|d| j	                  |      d| j                  |d      d	| j                  |d	      d
| j                  |d
      dd d| j                  |d      dd dd d|d|d|dd dd dd dd |||d|      S )N	timestampvolumevolume_quoteopenlastr  datetimehighlowbid	bidVolumeask	askVolumevwapclosepreviousClosechanger   average)
baseVolumequoteVolumer  )	parse8601safe_symbolr  safe_tickeriso8601)	r  rh  r  rj  r  r{  r|  rm  rn  s	            r  rY  zhitbtc.parse_ticker  s    NN6+#67	!!$/%%fh7
&&v~>// !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	r  sincer   c                 .   | j                          d}i }|t        |d      |d<   |||d<   d}|;| j                  |      }|d   |d<   | j                  | j	                  ||            }n!| j                  | j	                  ||            }|| j                  ||      S g }t        |j                               }	t        dt        |	            D ]A  }
|	|
   }| j                  |      }||   }| j                  ||      }| j                  ||      }C |S )a  
        get the list of most recent trades for a particular symbol

        https://api.hitbtc.com/#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   fromr  r  r   )r:  r  r  publicGetPublicTradesSymbolr>  publicGetPublicTradesparse_tradesr  r   r  r  array_concat)r  r  r  r   r  r  r?  r  tradesrd  r  rf  marketInner	rawTradesparseds                  r  fetch_tradeszhitbtc.fetch_trades  s1    	"5$/GG#GFO[[(F &tGH77GV8TUH11$++gv2NOH$$Xv66)	q#i.) 	7A |H++h/K *I&&y+>F&&vv6F	7 r  c                    | j                          d}i }|| j                  |      }|d   |d<   |||d<   |||d<   d}d}d}	| j                  d||      \  }}| j                  d|      \  }}| j	                  |ddg      }|"| j                  | j                  ||            }	n|d	k(  r"| j                  | j                  ||            }	nf|d
k(  r"| j                  | j                  ||            }	n?|dk(  r"| j                  | j                  ||            }	nt        | j                  dz         | j                  |	|||      S )a  
        fetch all trades made by the user

        https://api.hitbtc.com/#spot-trades-history
        https://api.hitbtc.com/#futures-trades-history
        https://api.hitbtc.com/#margin-trades-history

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported
        :param bool [params.margin]: True for fetching margin trades
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr  r  r   r  rn   r   r<   r;   r=   z- fetchMyTrades() not support self market typer:  r  handle_market_type_and_paramshandle_margin_mode_and_paramsr<  privateGetMarginHistoryTrader>  privateGetSpotHistoryTradeprivateGetFuturesHistoryTrader-   r  r  
r  r  r  r   r  r  r?  r   r   r  s
             r  fetch_my_tradeszhitbtc.fetch_my_trades  sk     	[[(F &tGH$GG#GFO

!??QWY_`
F!??QWX
F6L(#;<!88Wf9UVHV#::4;;wPV;WXv%==dkk'SY>Z[x'<<T[[RX=YZ"477-\#\]]  65%@@r  tradec                 n   | j                  |d         }| j                  |d      }| j                  ||      }|d   }d }| j                  |d      }| j                  |d      }||rdnd}	nd}	|;| j                  |di       }
| j                  |
d      }| j	                  |      }||d}| j                  |d	d
      }| j                  |d      }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  ||||| j                  |      |d ||	||d |d|      S )Nrj  r  r!  r   r   r  r  )r  r6  clientOrderIdclient_order_idr  quantityqtysider  )r  r  orderrj  ro  r  r  r  takerOrMakerr  r  r  r!  )r}  r  rb  r  r	  r  
safe_trader  )r  r  r  rj  rf  r  r!  feeCostStringr   r  r  r  feeCurrencyCodeorderIdpriceStringamountStringr  r  s                     r  parse_tradezhitbtc.parse_tradeC  st   r NN5#56	##E84!!(F3!((6w/&+7L"L$??6626D**4@K"55kBO%+C $$UO=NO&&ug6))%UCv.eT*"Y/( " 
  	r  c                 
   | j                          d|i}d }|| j                  |      }|d   |d<   || j                  |      |d<   |||d<   | j                  | j	                  ||            }| j                  |||||      S )Ntypesr  r,  r  r   )r:  r6  r  privateGetWalletTransactionsr>  parse_transactions)	r  r  r&  r  r   r  r?  r6  r  s	            r  fetch_transactions_helperz hitbtc.fetch_transactions_helper  s    U
 }}T*H$,TNGL!"ll51GFO$GG44T[[&5QR2 &&x5%PPr  statusc                 8    dddddd}| j                  |||      S )Npendingfailedok)CREATEDPENDINGFAILEDROLLED_BACKSUCCESSr  r  r  statusess      r  parse_transaction_statuszhitbtc.parse_transaction_status  s/      #
 &&99r  c                 2    ddd}| j                  |||      S )Nr"  
withdrawal)DEPOSITWITHDRAWr  )r  r  r  s      r  parse_transaction_typezhitbtc.parse_transaction_type  s&     $
 tT22r  transactionr6  c                    | j                  |dd      }| j                  | j                  |d            }| j                  | j                  |d            }| j                  | j                  |d            }| j	                  | j                  |d            }| j                  |di       }| j                  |d      }	| j                  |	      }
| j                  |d	      }| j                  |d
      }|}| j                  |d      }|}| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|dk(  }d d d d}| j                  |d      }|
|
|d<   ||d<   i d|d|d|d|d|
dd d|d|d|d| j                  |      d
|d|d|d|dd d|d|d ||dS ) Noperation_idr  
created_at
updated_atr  r  nativer6  hashr7  r8  sendersr   r  subtypeOFFCHAIN)r6  r  rater!  r  r  txidr  rj  ro  addressFrom	addressTor9  tagFromtagToupdated)commentinternalr!  )	r  r}  r  r  r  r  r	  r  r  )r  r  r6  r  rj  r  r  r  r  r-  r&  txhashr7  r  r9  r  senderr  r  subTyper  r!  feeCosts                          r  parse_transactionzhitbtc.parse_transaction  sv   B ^TBNN4#3#3K#NO	..!1!1+|!LM**4+;+;K+PQ..t/?/?X/VWh;%%fj9
&&z2!!&&1""695	v|43&&vq1!!&(3"";	:j( 

 ""651"C
O!CK
K
"
 F
 D	

 
 t
 f
 f
 
 Y/
 w
 ;
 
 3
 t
  U!
" w#
$  )
 	
r  c                 ,    | j                  d||||      S )a_  
        fetch history of deposits and withdrawals

        https://api.hitbtc.com/#get-transactions-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 is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        zDEPOSIT,WITHDRAWr  r  r&  r  r   r  s        r  fetch_deposits_withdrawalsz!hitbtc.fetch_deposits_withdrawals5  s     --.@$uV\]]r  c                 ,    | j                  d||||      S )a  
        fetch all deposits made to an account

        https://api.hitbtc.com/#get-transactions-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>`
        r  r  r  s        r  fetch_depositszhitbtc.fetch_depositsC  s     --iueVTTr  c                 ,    | j                  d||||      S )a  
        fetch all withdrawals made from an account

        https://api.hitbtc.com/#get-transactions-history

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  r  r  s        r  fetch_withdrawalszhitbtc.fetch_withdrawalsQ  s     --j$ufUUr  c                    | j                          i }|%| j                  |      }dj                  |      |d<   |||d<   | j                  | j	                  ||            }i }t        |j                               }t        dt        |            D ]Y  }	||	   }
||
   }| j                  |
      }| j                  | j                  |d            }| j                  ||
   ||dd      ||<   [ |S )aZ  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data for multiple markets

        https://api.hitbtc.com/#order-books

        :param str[] [symbols]: list of unified market symbols, all symbols fetched if None, default is None
        :param int [limit]: max number of entries per orderbook to return, default is None
        :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 symbol
        r^  r\  depthr   rj  rr  rt  )r:  r`  rU  publicGetPublicOrderbookr>  r  r   r  r  r~  r}  r  parse_order_book)r  r\  r   r  r?  marketIdsInnerr  r  rd  r  rf  	orderbookr  rj  s                 r  fetch_order_bookszhitbtc.fetch_order_books_  s     	!__W5N!$.!9GI$GG00Wf1MN)	q#i.) 	hA |H *I%%h/Ft'7'7	;'OPI!228H3EvyZ_afgF6N	h r  c                    | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  | j                  |d            }| j                  |||dd      S )a!  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://api.hitbtc.com/#order-books

        :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  rj  rr  rt  )r:  r  publicGetPublicOrderbookSymbolr>  r}  r  r  )r  r  r   r  r  r?  r  rj  s           r  fetch_order_bookzhitbtc.fetch_order_book|  s     	V$fTl
 $GG66t{{7F7STNN4#3#3Hk#JK	$$Xvy%OOr  r!  c                     | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }||||d d dS )Nr  r  r  )r  r  r   r   r   r   )r  r  r~  )r  r!  r  r   r   rf  r  s          r  parse_trading_feezhitbtc.parse_trading_fee  sh       k2  k2##C2!!(F3
 	
r  c                 R   | j                          | j                  |      }d|d   i}d}|d   dk(  r"| j                  | j                  ||            }nB|d   dk(  r"| j	                  | j                  ||            }nt        | j                  dz         | j                  ||      S )a  
        fetch the trading fees for a market

        https://api.hitbtc.com/#get-trading-commission
        https://api.hitbtc.com/#get-trading-commission-2

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r  r  Nr  r;   r=   z/ fetchTradingFee() not support self market type)r:  r  privateGetSpotFeeSymbolr>  privateGetFuturesFeeSymbolr-   r  r  rZ  s         r  fetch_trading_feezhitbtc.fetch_trading_fee  s     	V$fTl
 &>V#33DKK4PQHF^v%66t{{7F7STHtww)ZZ[[ %%h77r  c                 V   | j                          | j                  dd|      \  }}d}|dk(  r| j                  |      }n/|dk(  r| j                  |      }nt	        | j
                  dz         i }t        dt        |            D ]   }| j                  ||         }|d   }|||<   " |S )a  
        fetch the trading fees for multiple markets

        https://api.hitbtc.com/#get-all-trading-commissions
        https://api.hitbtc.com/#get-all-trading-commissions-2

        :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   Nr;   r=   z0 fetchTradingFees() not support self market typer   r  )	r:  r  privateGetSpotFeeprivateGetFuturesFeer-   r  r  r  r  )	r  r  r   queryr  r  r  r!  r  s	            r  fetch_trading_feeszhitbtc.fetch_trading_fees  s     	 >>?QSWY_`
E--e4H6!007Htww)[[\\ q#h-( 	!A((!5C]F F6N	! r  r   c           	         | j                          d}| j                  |dd      \  }}|r| j                  d|||||d      S | j                  |      }|d   | j	                  | j
                  ||      d}|| j                  |      |d<   | j                  d	||      \  }}|t        |d      |d
<   | j	                  |d      }	| j                  |d      }d}
|	dk(  r"| j                  | j                  ||            }
no|	dk(  r"| j                  | j                  ||            }
nH|	dk(  r"| j                  | j                  ||            }
n!| j                  | j                  ||            }
| j                  |
||||      S )ap  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://api.hitbtc.com/#candles
        https://api.hitbtc.com/#futures-index-price-candles
        https://api.hitbtc.com/#futures-mark-price-candles
        https://api.hitbtc.com/#futures-premium-index-candles

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding rate
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fro   paginater   r  )r  periodNr  untilr   r  markindexpremiumIndex)r:  handle_option_and_params"fetch_paginated_call_deterministicr  r  r  r  handle_until_optionr  r<  ,publicGetPublicFuturesCandlesMarkPriceSymbolr>  -publicGetPublicFuturesCandlesIndexPriceSymbol/publicGetPublicFuturesCandlesPremiumIndexSymbolpublicGetPublicCandlesSymbolparse_ohlcvs)r  r  	timeframer  r   r  r  r  r?  r  r  s              r  fetch_ohlcvzhitbtc.fetch_ohlcv  s   $ 	88zZ&::<QVX]_hjprvwwV$Tl&&t	9M
 "ll51GFO227GVL"5$/GG  167+F?HHU\^dIefHgII$++V]_eJfgHn$KKDKKX_agLhiH88Wf9UVH8   69eUKKr  c           	          | j                  | j                  |d            | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nrj  rm  r  r  rw  rk  )r}  r  r  )r  ohlcvr  s      r  parse_ohlcvzhitbtc.parse_ohlcv2  sw    2 NN4++E;?@UF+UE*UE*UG,UH-
 	
r  c                    | j                          d}i }|| j                  |      }|d   |d<   || j                  |      |d<   |||d<   d}d}| j                  d||      \  }}| j	                  d|      \  }}| j                  |ddg      }d}	|"| j                  | j                  ||            }	n|d	k(  r"| j                  | j                  ||            }	nf|d
k(  r"| j                  | j                  ||            }	n?|dk(  r"| j                  | j                  ||            }	nt        | j                  dz         | j                  |	|||      }
| j                  |
dddgd      S )a7  
        fetches information on multiple closed orders made by the user

        https://api.hitbtc.com/#spot-orders-history
        https://api.hitbtc.com/#futures-orders-history
        https://api.hitbtc.com/#margin-orders-history

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported
        :param bool [params.margin]: True for fetching margin orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r  r  r   rP   r   r<   r;   r=   z1 fetchClosedOrders() not support self market typer  closedcanceledF)r:  r  r  r  r  r<  privateGetMarginHistoryOrderr>  privateGetSpotHistoryOrderprivateGetFuturesHistoryOrderr-   r  parse_ordersfilter_by_array)r  r  r  r   r  r  r?  r   r   r  r  s              r  fetch_closed_orderszhitbtc.fetch_closed_ordersS  s     	[[(F &tGH"ll51GFO$GG

!??@SU[]cd
F!??@SU[\
F6L(#;<!88Wf9UVHV#::4;;wPV;WXv%==dkk'SY>Z[x'<<T[[RX=YZ"477-`#`aa""8VUEB##FHx6LeTTr  r  c                    | j                          d}|| j                  |      }d|i}d}d}| j                  d||      \  }}| j                  d|      \  }}| j	                  |ddg      }d}|"| j                  | j                  ||            }n|dk(  r"| j                  | j                  ||            }nf|dk(  r"| j                  | j                  ||            }n?|dk(  r"| j                  | j                  ||            }nt        | j                  dz         | j                  |d	      }	| j                  |	|      S )
a  
        fetches information on an order made by the user

        https://api.hitbtc.com/#spot-orders-history
        https://api.hitbtc.com/#futures-orders-history
        https://api.hitbtc.com/#margin-orders-history

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported
        :param bool [params.margin]: True for fetching a margin order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  rw   r   r<   r;   r=   z* fetchOrder() not support self market typer   )r:  r  r  r  r<  r
  r>  r  r  r-   r  	safe_dictparse_order)
r  r  r  r  r  r?  r   r   r  r  s
             r  fetch_orderzhitbtc.fetch_order  sS    	[[(Fr
 

!??fV\]
F!??fU
F6L(#;<!88Wf9UVHV#::4;;wPV;WXv%==dkk'SY>Z[x'<<T[[RX=YZ"477-Y#YZZ( x+v..r  c                 h   | j                          d}|| j                  |      }d|i}d}d}	| j                  d||      \  }}| j                  d|      \  }	}| j	                  |ddg      }d}
|	"| j                  | j                  ||            }
n|dk(  r"| j                  | j                  ||            }
nf|dk(  r"| j                  | j                  ||            }
n?|dk(  r"| j                  | j                  ||            }
nt        | j                  dz         | j                  |
|||      S )	a  
        fetch all the trades made from a single order

        https://api.hitbtc.com/#spot-trades-history
        https://api.hitbtc.com/#futures-trades-history
        https://api.hitbtc.com/#margin-trades-history

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported
        :param bool [params.margin]: True for fetching margin trades
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Norder_idr{   r   r<   r;   r=   z0 fetchOrderTrades() not support self market typer  )r  r  r  r  r   r  r  r?  r   r   r  s              r  fetch_order_tradeszhitbtc.fetch_order_trades  sL   " 	[[(F
 

!??@RTZ\bc
F!??@RTZ[
F6L(#;<!88Wf9UVHV#::4;;wPV;WXv%==dkk'SY>Z[x'<<T[[RX=YZ"477-_#_``N   65%@@r  c                 t   | j                          d}i }|| j                  |      }|d   |d<   d}d}| j                  d||      \  }}| j                  d|      \  }}| j	                  |ddg      }d}	|"| j                  | j                  ||            }	n|dk(  r"| j                  | j                  ||            }	nf|dk(  r"| j                  | j                  ||            }	n?|dk(  r"| j                  | j                  ||            }	nt        | j                  d	z         | j                  |	|||      S )
a  
        fetch all unfilled currently open orders

        https://api.hitbtc.com/#get-all-active-spot-orders
        https://api.hitbtc.com/#get-active-futures-orders
        https://api.hitbtc.com/#get-active-margin-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 orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported
        :param bool [params.margin]: True for fetching open margin orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r  rt   r   r<   r;   r=   z/ fetchOpenOrders() not support self market type)r:  r  r  r  r<  privateGetMarginOrderr>  privateGetSpotOrderprivateGetFuturesOrderr-   r  r  r  s
             r  fetch_open_orderszhitbtc.fetch_open_orders  sM     	[[(F &tGH

!??@QSY[ab
F!??@QSYZ
F6L(#;<!11$++gv2NOHV#33DKK4PQv%66t{{7F7STx'55dkk'66RS"477-^#^__(   65%@@r  c                 d   | j                          d}|| j                  |      }d|i}d}d}| j                  d||      \  }}| j                  d|      \  }}| j	                  |ddg      }d}|"| j                  | j                  ||            }n|dk(  r"| j                  | j                  ||            }nf|dk(  r"| j                  | j                  ||            }n?|dk(  r"| j                  | j                  ||            }nt        | j                  dz         | j                  ||      S )	a  
        fetch an open order by it's id

        https://api.hitbtc.com/#get-active-spot-order
        https://api.hitbtc.com/#get-active-futures-order
        https://api.hitbtc.com/#get-active-margin-order

        :param str id: order id
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported
        :param bool [params.margin]: True for fetching an open margin order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  rs   r   r<   r;   r=   z. fetchOpenOrder() not support self market type)r:  r  r  r  r<  "privateGetMarginOrderClientOrderIdr>   privateGetSpotOrderClientOrderId#privateGetFuturesOrderClientOrderIdr-   r  r  	r  r  r  r  r  r?  r   r   r  s	            r  fetch_open_orderzhitbtc.fetch_open_orderK  sG    	[[(Fr
 

!??@PRXZ`a
F!??@PRXY
F6L(#;<!>>t{{7TZ?[\HV#@@WV\A]^v%CCDKKPWY_D`ax'BB4;;wX^C_`"477-]#]^^&11r  c                 p   | j                          d}i }|| j                  |      }|d   |d<   d}d}| j                  d||      \  }}| j                  d|      \  }}| j	                  |ddg      }d}|"| j                  | j                  ||            }n|dk(  r"| j                  | j                  ||            }nf|dk(  r"| j                  | j                  ||            }n?|dk(  r"| j                  | j                  ||            }nt        | j                  d	z         | j                  ||      S )
a  
        cancel all open orders

        https://api.hitbtc.com/#cancel-all-spot-orders
        https://api.hitbtc.com/#cancel-futures-orders
        https://api.hitbtc.com/#cancel-all-margin-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.marginMode]: 'cross' or 'isolated' only 'isolated' is supported
        :param bool [params.margin]: True for canceling margin orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r  rA   r   r<   r;   r=   z/ cancelAllOrders() not support self market type)r:  r  r  r  r<  privateDeleteMarginOrderr>  privateDeleteSpotOrderprivateDeleteFuturesOrderr-   r  r  r  r  r  r  r?  r   r   r  s           r  cancel_all_orderszhitbtc.cancel_all_orderst  sG    	[[(F &tGH

!??@QSY[ab
F!??@QSYZ
F6L(#;<!44T[[&5QRHV#66t{{7F7STv%99$++gv:VWx'88Wf9UV"477-^#^__  622r  c                 d   | j                          d}d|i}|| j                  |      }d}d}| j                  d||      \  }}| j                  d|      \  }}| j	                  |ddg      }d}|"| j                  | j                  ||            }n|dk(  r"| j                  | j                  ||            }nf|dk(  r"| j                  | j                  ||            }n?|dk(  r"| j                  | j                  ||            }nt        | j                  dz         | j                  ||      S )	a  
        cancels an open order

        https://api.hitbtc.com/#cancel-spot-order
        https://api.hitbtc.com/#cancel-futures-order
        https://api.hitbtc.com/#cancel-margin-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
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported
        :param bool [params.margin]: True for canceling a margin order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  rB   r   r<   r;   r=   z+ cancelOrder() not support self market type)r:  r  r  r  r<  %privateDeleteMarginOrderClientOrderIdr>  #privateDeleteSpotOrderClientOrderId&privateDeleteFuturesOrderClientOrderIdr-   r  r  r   s	            r  cancel_orderzhitbtc.cancel_order  sE    	r
 [[(F

!??vW]^
F!??vV
F6L(#;<!AA$++gW]B^_HV#CCDKKPWY_D`av%FFt{{SZ\bGcdx'EEdkkRY[aFbc"477-Z#Z[[&11r  r  r  r  r  c                    | j                          d }|| j                  ||      d}	|dk(  s|dk(  r/|t        | j                  dz         | j	                  ||      |	d<   || j                  |      }d }
d }| j                  d||      \  }
}| j                  d|      \  }}| j                  |ddg      }d }|"| j                  | j                  |	|            }n|
d	k(  r"| j                  | j                  |	|            }nf|
d
k(  r"| j                  | j                  |	|            }n?|
dk(  r"| j                  | j                  |	|            }nt        | j                  dz         | j                  ||      S )N)r  r  r   	stopLimitz' editOrder() limit order requires pricer  rK   r   r<   r;   r=   z) editOrder() not support self market type)r:  amount_to_precisionr#   r  price_to_precisionr  r  r  r<  $privatePatchMarginOrderClientOrderIdr>  "privatePatchSpotOrderClientOrderId%privatePatchFuturesOrderClientOrderIdr-   r  )r  r  r  r  r  r  r  r  r  r?  r   r   r  s                r  
edit_orderzhitbtc.edit_order  s   !00@
 GO!4}#DGG.W$WXX#66vuEGG[[(F

!??VU[\
F!??VT
F6L(#;<!@@WV\A]^HV#BB4;;wX^C_`v%EEdkkRY[aFbcx'DDT[[QXZ`Eab"477-X#XYY&11r  c           
         | j                          | j                  |      }d}d}	| j                  d||      \  }	}d}
| j                  d|      \  }
}| j	                  ||	|||||
|      \  }}d}|	dk(  r"| j                  | j                  ||            }nJ|	dk(  s|
"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  ||      S )a   
        create a trade order

        https://api.hitbtc.com/#create-new-spot-order
        https://api.hitbtc.com/#create-margin-order
        https://api.hitbtc.com/#create-futures-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 str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported for spot-margin, swap supports both, default is 'cross'
        :param bool [params.margin]: True for creating a margin order
        :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.timeInForce]: "GTC", "IOC", "FOK", "Day", "GTD"
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NrE   r=   r<   )
r:  r  r  r  create_order_requestprivatePostFuturesOrderr>  privatePostMarginOrderprivatePostSpotOrderr  )r  r  r  r  r  r  r  r  r?  r   r   r  s               r  create_orderzhitbtc.create_order  s   * 	V$
!??vW]^
F
!??vV
F33FJdTZ\acmouv33DKK4PQHH$**@224;;w3OPH00Wf1MNH&11r  r   r   c	                 R   |dk(  }	| j                  |d      }
| j                  |d      }| j                  |g d      }| j                  |dk(  d |      }||| j	                  |d   |      |d   d}|
1|d	   d
k7  r)|d	   dk7  r!t        | j                  dz   |d	   z   dz         |
du r|
|d<   |rd|d<   |||d<   |	s
|dk(  s|dk(  r2|t        | j                  dz         | j                  |d   |      |d<   |dk(  r,| j                  |d      }|t        | j                  dz         |+| j                  |d   |      |d<   |	rd|d	<   n7|dk(  r2d|d	<   n,|dk(  s|dk(  s
|dk(  s|dk(  rt        | j                  dz         | j                  |g d      }|d
k(  r	|d}||d<   ||gS ) Nr   
reduceOnlyr   )r   	stopPrice
stop_pricer  r  r  )r  r  r  r  r  r=   r<   z0 createOrder() does not support reduce_only for zJ orders, reduce_only orders are supported for swap and margin markets onlyTreduce_only	post_onlytime_in_forcer.  takeProfitLimitz9 createOrder() requires a price argument for limit ordersr  r   expire_timez@ createOrder() requires an expire_time parameter for a GTD orderr>  
stopMarkettakeProfitMarketzU createOrder() requires a triggerPrice parameter for stop-loss and take-profit orders)r   r   r=  r>  r<  postOnlycrossmargin_mode)
r  r  safe_number_nis_post_onlyr/  r+   r  r#   r0  r<  )r  r  r   r  r  r  r  r   r  isLimitr<  r   r   
isPostOnlyr?  
expireTimes                   r  r6  zhitbtc.create_order_request
	  s:   7?__V\:
&&v}=))&2]^&&tx'7vF
001A6JTl	
" !v&(vf~/I"477-_#_bhiobp#p  t@  $@  A  A%/GM"#'GK "'2GO$t{*8I0I}#DGG.i$ijj#66vh7GOGG5 ))&-@J!#DGG.p$pqq#$($;$;F8<Ll$[GL!"-!".k!t|';IZAZ`dhz`z  +B  !B  C  C6#wx!$
%/GM"  r  c                 :    ddddddd}| j                  |||      S )Nrm  r  r	  r  )new	suspendedpartiallyFilledfilledr	  expiredr  r  s      r  parse_order_statuszhitbtc.parse_order_statusB	  s2    %"
 &&99r  r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |	      }
| j                  |d      }d }||	k7  r| j                  |      }| j                  |d	      }| j                  | j                  |d
            }| j                  |d      }| j                  ||      }|d   }| j	                  |d      }| j                  |d      }| j	                  |d      }| j                  i d|d|d|d|
d| j                  |
      d|d|d|d|d|d|d|d|d|d| j	                  |d      d|dd d |||d | j                  |d      d d d|      S )Nr  r  r  r  r  price_averager  r  quantity_cumulativer  r  r@  rA  r  r  r  r  rj  ro  lastTradeTimestamplastUpdateTimestampr  r   rF  r<  r?  rR  	remainingr>  )r  r  rz  r  r!  r   r   r   )r  r}  rT  rb  r  
safe_orderr  )r  r  r  r  r  r  r  r  rz  r  rj  r  rX  rR  r  rf  r  rF  r   r  s                       r  r  zhitbtc.parse_orderM	  sx   D e%67 v.v.!!%4  0""5/:""5,7NN7+	""5,7!g!%!8!!%)>?(()9)9%)JK##E84!!(F3!??5+6&&uo>OOE84	  
E 
" 
 R 
 	 

 Y/ 
 !"4 
 "#5 
 f 
 U 
 f 
 D 
 D 
 ; 
  
 $//%? 
  f! 
" # 
$  ,,ULA#!3 
4 5 	r  c                    | j                          d}|%| j                  |      }| j                  |d         }d}| j                  d||      \  }}d}|dk(  r| j	                  |      }n/|dk(  r| j                  |      }nt        | j                  dz         | j                  |dg       }| j                  ||d      S )	a  
        fetches margin mode of the user

        https://api.hitbtc.com/#get-margin-position-parameters
        https://api.hitbtc.com/#get-futures-position-parameters

        :param str[] symbols: unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `margin mode structures <https://docs.ccxt.com/#/?id=margin-mode-structure>`
        Nr   rg   r<   r=   z; fetchMarginModes() supports swap contracts and margin onlyconfigr  )
r:  r_  r  r  privateGetMarginConfigprivateGetFuturesConfigr)   r  r(  parse_margin_modes)r  r\  r  r  r   r  r]  s          r  fetch_margin_modeszhitbtc.fetch_margin_modes	  s     	))'2G[[,F
!??@QSY[ab
F!226:H$ 6!33F;H& DGG&ccdd(B7&&vwAAr  c                 r    | j                  |d      }|| j                  ||      | j                  |d      dS )Nr  rH  )r  r  r   )r  r~  rQ  )r  r   r  rf  s       r  parse_margin_modezhitbtc.parse_margin_mode 
  sA    ##J9&&x800]K
 	
r  fromAccount	toAccountc                    | j                          | j                  |      }| j                  ||      }| j                  | j                  di       }|j                         }|j                         }| j                  |||      }	| j                  |||      }
|	|
k(  rt        | j                  dz         |d   ||	|
d}| j                  | j                  ||            }| j                  ||      S )a  
        transfer currency internally between wallets on the same account

        https://api.hitbtc.com/#transfer-between-wallet-and-exchange

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r  zJ transfer() fromAccount and toAccount arguments cannot be the same accountr  )r6  r  sourcedestination)r:  r6  currency_to_precisionr  r  lowerr  r(   r  privatePostWalletTransferr>  parse_transfer)r  r&  r  rd  re  r  r6  requestAmountr  fromIdtoIdr?  r  s                r  r   zhitbtc.transfer
  s     	==&224@7GL!'')OO%	!!.+{K	9ET>TWW'sstt #	
 11$++gv2NO ""8X66r  r   c           
      Z    | j                  |d      d d | j                  d |      d d d d |d	S )Nr   )	r  rj  ro  r6  r  rd  re  r  r  )r  r	  )r  r   r6  s      r  rl  zhitbtc.parse_transfer.
  sC     ""8Q///h?

 
	
r  c                 \   | j                          |dk7  rt        | j                  dz         | j                  | j                  di       }|j                         }|j                         }| j                  ||      }| j                  ||      }||k(  rt        | j                  dz         ||Ct        |j                               }t        | j                  dz   dj                  |      z         ||| j                  ||      d}| j                  | j                  ||            }	d|	iS )	Nr,  z6 convertCurrencyNetwork() only supports USDT currentlyr  z8 convertCurrencyNetwork() fromNetwork cannot be the samezm convertCurrencyNetwork() requires a fromNetwork parameter and a toNetwork parameter, supported networks are rP  )from_currencyto_currencyr  r  )r:  r#   r  r  r  r*  r  r(   r  r   r'   rU  ri  privatePostWalletConvertr>  )
r  r&  r  fromNetwork	toNetworkr  r  r   r?  r  s
             r  convert_currency_networkzhitbtc.convert_currency_networkB
  sK   6>*b bcc??4<<R@!'')OO%	&&x=$$Xy9	)#TWW'aabbY%6(D#DGG  /^  %^  ae  aj  aj  ko  ap  %p  q  q($00v>

 00Wf1MN H
 	
r  r7  c                 F   | j                  ||      \  }}| j                          | j                  |       | j                  |      }|d   ||d}|||d<   | j	                  | j
                  di       }| j                  |d      }	|	0|dk(  r+| j                  ||	      }
|
|
|d<   | j                  |d      }| j	                  | j
                  di       }| j                  |d	d
      }|rd|d<   | j                  | j                  ||            }| j                  ||      S )a  
        make a withdrawal

        https://api.hitbtc.com/#withdraw-crypto

        :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  )r6  r  r7  r8  r  r  r,  network_coder   r  FTinclude_fee)handle_withdraw_tag_and_paramsr:  check_addressr6  r  r  r;  r  r<  r  privatePostWalletCryptoWithdrawr>  r  )r  r&  r  r7  r9  r  r6  r?  r  r  r@  withdrawOptionsr  r  s                 r  r   zhitbtc.withdraw[
  s2    99#vFV7#==& 

 ?$'GL!??4<<R@((;dfn ,,Xw?M(*7'YYvy1F//$,,
BG^^O\5I
%)GM"77GV8TU %%h99r  c                    | j                          d}i }|J| j                  |      }| j                  |d         }| j                  |      }dj	                  |      |d<   d}| j                  d||      \  }}|dk7  rt        | j                  dz   |z   dz         | j                  | j                  ||            }t        |j                               }i }	t        dt        |            D ]S  }
| j                  ||
      }| j                  ||      }| j                  |      }|d	   }| j!                  ||      }||	|<   U | j#                  |	d	|      S )
a  
        fetches funding rates for multiple markets

        https://api.hitbtc.com/#futures-info

        :param str[] symbols: unified symbols of the markets to fetch the funding rates for, all market funding rates are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        Nr   r^  r\  r_   r=   z& fetchFundingRates() does not support z marketsr  )r:  r_  r  r`  rU  r  r-   r  publicGetPublicFuturesInfor>  r  r   r  r  r  r  parse_funding_rater  )r  r\  r  r  r?  queryMarketIdsr  r  rd  fundingRatesr  rf  rawFundingRater  r  fundingRates                   r  fetch_funding_rateszhitbtc.fetch_funding_rates
  sc    	))'2G[[,F!__W5N!$.!9GI99:MvW]^f6>tww)QQTXX[eeff224;;w3OP$ )	q#i.) 	/A''	15H!__Xx@N++h/K *F11.+NK#.L 	/ ##L(GDDr  c           
      <   | j                          d}| j                  |dd      \  }}|r| j                  d|||d|d      S d}i }| j                  d||      \  }}|| j	                  |      }|d   }|d	   |d
<   |||d<   |||d<   | j                  | j                  ||            }t        |j                               }	g }
t        dt        |	            D ]  }|	|   }| j                  |      }||   }t        dt        |            D ]e  }||   }| j                  |d         }| j                  |d      }| j                  |d      }|
j                  |||| j!                  |      |d       g  | j#                  |
d      }| j%                  ||||      S )a  

        https://api.hitbtc.com/#funding-history

        fetches historical funding rate prices
        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding rate
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Fr^   r  8hr   Nr  r  r  r\  r  r   r   funding_raterj  )r  r  r  rj  ro  )r:  r  r  r  r  $publicGetPublicFuturesHistoryFundingr>  r  r   r  r  rb  r~  r  r  r
  r}  sort_byfilter_by_symbol_since_limit)r  r  r  r   r  r  r  r?  r  	contractsratesr  rf  r  fundingRateDatar0  r.  symbolInnerr  ro  sorteds                        r  fetch_funding_rate_historyz!hitbtc.fetch_funding_rate_history
  s    	88AZ\fg&::;TV\^cejlprxz~
 227GVL[[(FH%F!'GI#GFO$GG<<T[[RX=YZ  )	q#i.) 	A |H**84K&x0O1c/23 '*"..{8/DE"..unE++E;?!)#.!%!9 ( 		  e[100NNr  c                 T   | j                          i }d}d}| j                  dd|      \  }}|dk(  rd}| j                  d|      \  }}| j                  |ddg      }d}|"| j	                  | j                  ||            }nf|dk(  r"| j                  | j                  ||            }n?|dk(  r"| j	                  | j                  ||            }nt        | j                  dz         g }t        dt        |            D ]%  }|j                  | j                  ||                ' |S )	a~  
        fetch all open positions

        https://api.hitbtc.com/#get-futures-margin-accounts
        https://api.hitbtc.com/#get-all-margin-accounts

        :param str[]|None symbols: not used by hitbtc fetchPositions()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported, defaults to spot-margin endpoint if self is set
        :param bool [params.margin]: True for fetching spot-margin positions
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr}   r;   r=   r   r<   z. fetchPositions() not support self market typer   )r:  r  r  r<  privateGetMarginAccountr>  privateGetFuturesAccountr-   r  r  r  r
  parse_position)	r  r\  r  r?  r   r   r  r  r  s	            r  fetch_positionszhitbtc.fetch_positions  s9    	

!??@PRVX^_
FJ!??@PRXY
F6L(#;<!33DKK4PQHV#88Wf9UVx'77GV8TU"477-]#]^^B q#h-( 	<AMM$--hqk:;	<r  c                    | j                          | j                  |      }d|d   i}d}d}| j                  dd|      \  }}| j                  d|      \  }}| j	                  |ddg      }d}|"| j                  | j                  ||            }nf|dk(  r"| j                  | j                  ||            }n?|dk(  r"| j                  | j                  ||            }nt        | j                  dz         | j                  ||      S )	a  
        fetch data on a single open contract trade position

        https://api.hitbtc.com/#get-futures-margin-account
        https://api.hitbtc.com/#get-isolated-margin-account

        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported, defaults to spot-margin endpoint if self is set
        :param bool [params.margin]: True for fetching a spot-margin position
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        r  r  Nr|   r   r<   r=   z- fetchPosition() not support self market type)r:  r  r  r  r<  %privateGetMarginAccountIsolatedSymbolr>  &privateGetFuturesAccountIsolatedSymbolr-   r  r  r&  s           r  fetch_positionzhitbtc.fetch_positionI  s    	V$fTl
 

!??QUW]^
F!??QWX
F6L(#;<!AA$++gW]B^_HV#FFt{{SZ\bGcdx'EEdkkRY[aFbc"477-\#\]]B ""8V44r  positionc                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |dg       }d }d }d }	t        dt	        |            D ]=  }
||
   }| j                  |d      }| j                  |d      }| j                  |d      }	? | j                  |d	g       }d }t        dt	        |            D ]  }
||
   }| j                  |d
      } | j                  |d      }| j                  ||      }|d   }| j                  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| j                  |      |d d d |d d |d d d d      S )Nr  r   r  	positionsr   price_liquidationprice_entryr  r,  margin_balancer  r  r  notionalr   
marginTypeliquidationPrice
entryPriceunrealizedPnlr   r  r  	markPrice	lastPricer  r   rj  )ro  rY  maintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager   marginRatior   r   )r  r  r  r  r  rb  safe_positionr}  )r  r  r  r   r   ro  r  r  r  r  r  r.  r,  r  rf  r  s                   r  r  zhitbtc.parse_position  sK   B %%h7
##Hj9##Hl;OOHk2>	
	q#i.) 	<AaLE#//7JK))%?J((
;I		<
 __X|R@

q#j/* 	CAqME))%1ABJ	C ##Hh7!!(F3!!! #
H#
$#
 f#
 	#

 *#
 *#
  0#
 *#
 T#
 $#
 #
 D#
 #
 #
 D#
  d!#
" 1##
$ !#'!%+/$!'+ !#9#
  	r  c           	          | j                  |d      }| j                  |d      }| j                  | j                  d |      d || j	                  |      ||d|      S )Nrj  open_interest)r  openInterestAmountopenInterestValuerj  ro  r  )r  r  safe_open_interestr~  r}  )r  interestr  ro  values        r  parse_open_interestzhitbtc.parse_open_interest  sm      ##Hk:  ?;&&&&tV4"&!&1 (
  	r  c                    | j                          i }| j                  |      }d}|%| j                  |      }dj                  |      |d<   | j	                  | j                  ||            }g }t        |j                               }t        dt        |            D ]<  }||   }	| j                  |	      }
|j                  | j                  ||	   |
             > | j                  |d|      S )ag  
        Retrieves the open interest for a list of symbols

        https://api.hitbtc.com/#futures-info

        :param str[] [symbols]: a list of unified CCXT market symbols
        :param dict [params]: exchange specific parameters
        :returns dict[]: a list of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
        Nr^  r\  r   r  )r:  r_  r`  rU  r  r>  r  r   r  r  rb  r
  r  r  )r  r\  r  r?  rd  r  resultsmarketsr  rf  r  s              r  fetch_open_interestszhitbtc.fetch_open_interests  s     	%%g.	0I!$)!4GI224;;w3OP$ x}}'q#g,' 	VAqzH**84KNN433HX4FTU	V ##GXw??r  c                     | j                          | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||            }| j                  ||      S )aZ  
        Retrieves the open interest of a derivative trading pair

        https://api.hitbtc.com/#futures-info

        :param str symbol: Unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=interest-history-structure:
        r=   z1 fetchOpenInterest() supports swap contracts onlyr  r  )r:  r  r)   r   publicGetPublicFuturesInfoSymbolr>  r  rZ  s         r  fetch_open_interestzhitbtc.fetch_open_interest&  s|     	V$f~DGG&YYZZfTl
 88Wf9UV  ''&99r  c                     | j                          | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||            }| j                  ||      S )aL  
        fetch the current funding rate

        https://api.hitbtc.com/#futures-info

        :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=   z0 fetchFundingRate() supports swap contracts onlyr  r  )r:  r  r)   r  r  r>  r  rZ  s         r  fetch_funding_ratezhitbtc.fetch_funding_rateI  s|     	V$f~DGG&XXYYfTl
 88Wf9UV  &&x88r  c                    | j                  |d      }| j                  |d      }i d|d| j                  d |      d| j                  |d      d| j                  |d      d	| j                  |d
      d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 iS )Nnext_funding_timerj  r  r  r  
mark_price
indexPriceindex_priceinterestRateinterest_rateestimatedSettlePricero  r  r  fundingTimestampfundingDatetimenextFundingRateindicative_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  r~  r  r}  )r  r  r  fundingDateTimero  s        r  r  zhitbtc.parse_funding_ratel  sh     **85HI##Hk:
H
d&&tV4
 ))(LA
 $**8]C	

 D,,XG
 #D
 1
 
 4++HnE
  ?
 
 t//:ST
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                    | j                          | j                  |      }| j                  |d      }|d   r|t        | j                  dz         | j                  |      }|dk7  r| j                  ||      }nd}|d   |d}|||d<   d }	d }
| j                  d||      \  }	}| j                  d|      \  }
}d }|	dk(  r"| j                  | j                  ||            }nI|	dk(  s
|	d	k(  s|
d
k(  r"| j                  | j                  ||            }nt        | j                  dz         | j                  | j                  ||      | j                  |      |d      S )Nr   r=   zD modifyMarginHelper() requires a leverage parameter for swap marketsr   r  )r  r  modifyMarginHelperr<   r;   isolatedz2 modifyMarginHelper() not support self market type)r  r  )r:  r  r  r'   r  number_to_stringr/  r  r  &privatePutFuturesAccountIsolatedSymbolr>  %privatePutMarginAccountIsolatedSymbolr-   parse_margin_modificationr  )r  r  r  r  r  r  r   stringAmountr?  r   r   r  s               r  modify_margin_helperzhitbtc.modify_margin_helper  s   V$##FJ7&>'2x(xyy,,V43--flCFFTl$
 "*GJ

!??@TV\^de
F!??@TV\]
FBB4;;wX^C_`HH$**>JR\D\AA$++gW]B^_Htww)]]^^& {{499(FK''/N
  	r  datac                     | j                  |dg       }| j                  |d      }| j                  |d      }||d   d dd d | j                  |d      d | j                  |      |d
S )Nr,  r   r  r  r  r&  )
r  r  r  r   r  totalr&  r  rj  ro  )r  r  r}  )r  r  r  r,  currencyInforo  s         r  r  z hitbtc.parse_margin_modification  s{    * __T<<
z15##D,7X&$$$\6:1 
 	
r  c                     | j                  |      dk7  rt        | j                  dz         | j                  ||d|      S )a  
        remove margin from a position

        https://api.hitbtc.com/#create-update-margin-account-2
        https://api.hitbtc.com/#create-update-margin-account

        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported, defaults to the spot-margin endpoint if self is set
        :param bool [params.margin]: True for reducing spot-margin
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        r   zc reduceMargin() on hitbtc requires the amount to be 0 and that will remove the entire margin amountreduce)r  r(   r  r  r  r  r  r  s       r  reduce_marginzhitbtc.reduce_margin  sO       (C/TWW  (M  M  N  N((6JJr  c                 *    | j                  ||d|      S )a  
        add margin

        https://api.hitbtc.com/#create-update-margin-account-2
        https://api.hitbtc.com/#create-update-margin-account

        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported, defaults to the spot-margin endpoint if self is set
        :param bool [params.margin]: True for adding spot-margin
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        add)r  r  s       r  
add_marginzhitbtc.add_margin   s     ((GGr  c                 D   | j                          | j                  |      }d|d   i}d}| j                  d|      \  }}| j                  |ddg      }d}|"| j	                  | j                  ||            }n|d   dk(  r"| j	                  | j                  ||            }nl|d   d	k(  r"| j                  | j                  ||            }nB|d   dk(  r"| j	                  | j                  ||            }nt        | j                  d
z         | j                  ||      S )ao  
        fetch the set leverage for a market

        https://api.hitbtc.com/#get-futures-margin-account
        https://api.hitbtc.com/#get-isolated-margin-account

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' only 'isolated' is supported, defaults to the spot-margin endpoint if self is set
        :param bool [params.margin]: True for fetching spot-margin leverage
        :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
        r  r  Nrd   r   r<   r  r;   r=   z- fetchLeverage() not support self market type)
r:  r  r  r<  r  r>  r  r-   r  parse_leverage)r  r  r  r  r?  r   r  s          r  fetch_leveragezhitbtc.fetch_leverage  s.    	V$fTl
 
!??QWX
F6L(#;<!AA$++gW]B^_Hf~'EEdkkRY[aFbc6)FFt{{SZ\bGcd8+EEdkkRY[aFbc"477-\#\]]> ""8V44r  r   c                     | j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      ||dS )Nr  r   r  )r  r  r   longLeverageshortLeverage)r  r  r~  rQ  )r  r   r  rf  leverageValues        r  r  zhitbtc.parse_leverageQ  sY    ##Hh7))(J?&&x8006B)*
 	
r  c                 6   |t        | j                  dz         | j                          |d   t        | j                  dz         | j                  |      }| j	                  |d      }| j                  |d   d   dd      }|d   d	k7  rt        | j                  d
z         |dk  s||kD  r*t        | j                  dz   t        |      z   dz   |z         |d   t        |      | j                  ||      d}| j                  | j                  ||            S )ae  
        set the level of leverage for a market

        https://api.hitbtc.com/#create-update-margin-account-2

        :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() requires a symbol argumentr  zj setLeverage() requires a margin_balance parameter that will transfer margin to the specified trading pairr  r   r  2   r  r=   z+ setLeverage() supports swap contracts onlyr   z0 setLeverage() leverage should be between 1 and z for r  )r  r   r  )r'   r  r:  r  r  r  r)   r(   strr/  r  r>  )r  r   r  r  r  r  maxLeverager?  s           r  set_leveragezhitbtc.set_leverage\  s<    >#DGG.Y$YZZ"#+#DGG  /[  %[  \  \V$!!&*:;''x(8(DeRP&>V#DGG&SSTTqLh4TWW'YY\_`k\llovvy  A  ATlH"66vvF
 ::4;;wPV;WXXr  codesc                 h    | j                          | j                  |      }| j                  ||      S )aT  
        fetch deposit and withdraw fees

        https://api.hitbtc.com/#currencies

        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fees structures <https://docs.ccxt.com/#/?id=fee-structure>`
        )r:  r'  parse_deposit_withdraw_fees)r  r  r  r  s       r  fetch_deposit_withdraw_feesz"hitbtc.fetch_deposit_withdraw_fees{  s5     	//74 //%@@r  c                    | j                  |dg       }| j                  |      }t        dt        |            D ]  }||   }| j	                  |d      }| j                  |      }||j                         nd }| j                  |d      }	| j                  |d      }
|	|	dnd d}|
du r||d	<   |d d dd
|d   |<    |S )Nr  r   r  r  r   F)r!  r   Tr   )r   r"  )r  deposit_withdraw_feer  r  r  r)  r*  r  )r  r!  r6  r  r  r0  networkEntryr2  r3  withdrawFee	isDefaultwithdrawResults               r  parse_deposit_withdraw_feez!hitbtc.parse_deposit_withdraw_fee  s    0 ??3
B7**3/q#h-( 	A#A;L((yAI11)<K2=2I+++-PTK**<FKi@I"(3(?ed$N D %3z"*"&/F:{+	( r  c                     | j                          d}| j                  d|d      \  }}| j                  |      }|d   |d}| j                  | j	                  ||            }| j                  ||      S )a  
        closes open positions for a market

        https://api.hitbtc.com/#close-all-futures-margin-positions

        :param str symbol: unified ccxt market symbol
        :param str side: 'buy' or 'sell'
        :param dict [params]: extra parameters specific to the okx api endpoint
        :param str [params.symbol]: *required* unified market symbol
        :param str [params.marginMode]: 'cross' or 'isolated', default is 'cross'
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NrC   rG  r  )r  rH  )r:  r  r  ,privateDeleteFuturesPositionMarginModeSymbolr>  r  )r  r  r  r  r   r  r?  r  s           r  close_positionzhitbtc.close_position  s     	
!??QWY`a
FV$Tl%
 DDT[[QXZ`Eab  &11r  c                     | j                  | j                  d      }| j                  |dd      }d}t        t        |   |||      \  }}||dk(  s|du rd}||gS )aR  
 @ignore
        marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Array: the marginMode in lowercase
        defaultTyper<   FNTr  )r  r  r  r  r4   r  )r  
methodNamer  defaultValuer  isMarginr   r  s          r  r  z$hitbtc.handle_margin_mode_and_params  ss     &&t||]C>>&(E:
"64Nz[acop
Fx'X-='
F##r  reasonurlmethodheadersbodyc
                 0   | j                  |d      }
| j                  |
d      }|p| j                  dz   |z   }| j                  |
dd      }| j	                  | j
                  d   ||       | j                  | j
                  d   ||       t        |      y )Nerrorr&   messagedescriptionr'  r(  )r  r  r  r  throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr#   )r  r&  r  r  r	  r
  r  r  requestHeadersrequestBodyr  	errorCodefeedbackr  s                 r  handle_errorszhitbtc.handle_errors	  s    " '2$$UF3	 ww}t+H((	=IG001I9V^_001I7T\]))r  r   r  c                 V   | j                  || j                  |            }| j                  ||      }| j                  d   |   dz   |z   }	d }
t	        |j                               }t        |      }ddi}|dk(  r|r+d| j                  |      z   }
|	|
z   }	n| j                  |      }|dk(  r| j                          t        | j                               }|d|z   g}|dk(  r|
#|j                  |
       n|j                  |       |j                  |       d	j                  |      }| j                  | j                  |      | j                  | j                         t"        j$                  d
      }| j&                  dz   |z   dz   |z   }| j)                  |      }d|z   |d<   |	|||dS )Nr   r  zContent-Typezapplication/jsonr  ?r   z/api/3/ hexr  zHS256 Authorization)r  r	  r  r
  )r<  extract_paramsimplode_paramsr  r  r   r  	urlencodejsoncheck_required_credentialsr  r  r
  rU  hmacencodesecrethashlibsha256apiKeystring_to_base64)r  pathr   r	  r  r
  r  r  implodedPathr  
getRequestr   queryLengthrj  payloadpayloadString	signaturesecondPayloadencodeds                      r  signzhitbtc.sign$  s   		&$"5"5d";<**48iis#c)L8
EJJL!$i.
 U? 4>>%#88
J&99V$D)++-DJJL)Iy<78G)NN:.t$NN9%GGG,M		$++m"<dkk$++>VX_XfXfhmnI KK#-	9C?)KM++M:G'/''9GO$fdwOOr  r  )m__name__
__module____qualname__r   r  r  r"   r   r  r   r4  r  r	   rA  rF  r   rN  rV  r   r[  r   r   rg  dictrY  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   r4  floatr:  objectr6  rT  r  r   ra  r   rc  r!   r   rl  rw  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  intr  r2  __classcell__)r  s   @r  r4   r4      sb   j# jX# $& I$v, IV ') dZ dL 8: !
3 !
n !
F 79 %
# %
^ %
N
) 
) $& $,( $,L 02 33 3f 3> 04B )GW )G7 )GV)4 ) )6 )V 6:UW $3 $s $# $\`af\g $L -1tRV_a +Ac +A +AC +AZc cv c cJ&QP:s :3R
T R
X R
Q\ R
h 6:[_hj ^s ^# ^UX ^ost  pA ^ *.Dt\^ U3 Uc U Ucghsct U -1tRV_a Vc V VC Vfjkvfw V 48dSU   Zd : :>b Ps P3 PY P,
T 
6 
EX 
* 57 8 8;N 8> )+ !{ !F 26DW[df GL# GLc GLQT GLkoptku GLR
 
4 
B 154VZce ,U# ,US ,UPS ,Ujnotju ,U\ 26b ;/c ;/3 ;/z 9=4^bkm OAS OA# OAS OAX[ OAb /3TXac :A :A3 :Ac :Ahlmrhs :Ax 7;2 '23 '2 '2R /32 %3 %3N 37r '2s '2C '2R `drv  @B 2S 2# 2Y 2i 2Y\ 2lo 2@ gksu $23 $2i $2y $2RW $2`c $2L CG  [_  hj 6!6 6!s 6!) 6![d 6!ns 6!| 6!  UX 6!p	: 	:s sv s sj 7;2 <B$s) <B+ <B|
D 
* 
 [] $7S $7% $7c $7c $7an $7L
t 
x 
= 
(
S 
2 DHPR ):S ):% ):# ):Wb ):V 6:" 1E7 1E 1Ef 8<$]ajl IO IOC IOWZ IOV 26b Cw CT(^ CJ 24 A5S A5FRt RV RhF 6 7;2 )@G )@V 79 !:# !:F 68 !9 !9K !9F%
6 %
[ %
N FH 43 4L^ 4l#
d #
F #
N` #
J @B KC K KFX K$ =? H He HCU H  24 ?5S ?5 ?5B	
t 	
V 	
x 	
 9=R YS Y# Y> <@ %A %AN. .` =A %2S %2	 %2PU %2N @BPT $ # s  c TX `c 6 &eBSW Pr  r4   )9ccxt.base.exchanger   ccxt.abstract.hitbtcr   r%  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   typingr"   ccxt.base.errorsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   ccxt.base.decimal_to_precisionr1   ccxt.base.preciser2   r4    r  r  <module>rC     s    ( ,  V  V  V  V  V  V  V  V  * 0 - - . ' & . ) * ) . 1 * 4 %f8PX{ f8Pr  