
    iT                    t   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 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m*Z* d dlm+Z+ d dlm,Z, d dlm-Z- d dl.m/Z/ d dl0m1Z1  G d dee          Z2dS )    )Exchange)ImplicitAPIN)Balances
CurrenciesCurrencyIntLeverage
MarginModeMarginModesMarginModificationMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)	TICK_SIZE)Precisec                       e Zd Z fdZd Zi fdee         fdZi fdefdZ	d Z
i fdefdZi f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d]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d]dedefdZd Zd Zd Zd]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fd Z&di fdedede'fd!Z(d]dede)fd"Z*i fdede)fd#Z+i fde,fd$Z-d%ddi fdedededee.         fd&Z/d]dede.fd'Z0dddi fdedededee1         fd(Z2di fd)edefd*Z3dddi fd)edededefd+Z4dddi fdedededee1         fd,Z5di fd)edefd-Z6di fdefd.Z7di fd)edefd/Z8ddi fd)eded0e9d1e:d2e;d3e;fd4Z<di fded0e9d1e:d2e=d3e;f
d5Z>ddi fde?d6ed0e9d1e:d2e=d3e;d7efd8Z@d9 ZAd]dede1fd:ZBdi fdee         deCfd;ZDd]deEfd<ZFi fded2e=d=ed>edeGf
d?ZHd]de fd@ZIdefdAZJdi fded2e=fdBZKdi fdefdCZLdddi fdededefdDZMdi fdefdEZNi fdefdFZOd]defdGZPd]defdHZQi fdefdIZRi fdefdJZSd]defdKZTi fdedeUfdLZVd]dedeUfdMZWi fdedeUfdNZXi fdedeUfdOZYi fdedeZfdPZ[d]deZfdQZ\di fdRedefdSZ]di fdTefdUZ^d]de fdVZ_di fded1e:de1fdWZ`i df fdX	ZadY ZbdZd[i ddfd\Zc xZdS )^hitbtcc                 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	d	d	dddd	d	dMt          dNdOdOdPdQdQdPdRdSdTdUgdVdWgdXdYi dZd[d\d[d]d[d^d[d_d[d`d[dad[dbd[dcd[ddd[ded[dfd[dgd[dhd[did[djd[dkd[d[d[d[d[d[d[d[d[d[d[d[d[d[dlii dmdndodndpdqdrdqdsdndtdndudndvdndwdqdxdqdydqdzdqd{dqd|dnd}dnd~dnddni ddnddnddnddqddqddqddqddnddnddnddnddnddnddndddddddddddddddndndndndi dpdqddqdzdqddqddqddqddddddddddddddddddnddnddnddnidqdqdqddqdqdqdqdqdqdqdqdqdqdddqdqddddPdd	d	|                     d          |                     d          |                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg
|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg
ddi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          dt          dt          dt          dt          dt          dt          dt"          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          di dddddi dd ddddddddddddddddd	d	d
d
ddddddddd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+d,d,d-d-d.d.d/d/d0d0d1d1d2d3d4d5d6d6d7d7d8d9d:d:i d;d;d<d<d=d=d>d>d?d?d@dAdBdBdCdDdEdEdFdFdGdHdIdIdJdJdKdKdLdLdMdMdNdOi dPdPdQdQdRdRdSdSdTdTdUdUdVdVdWdXdYdYdZd[d\d\d]d]d^d^d_d_d`d`dadadbdbdcdciddddedfdgdidhi didjdkdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddddddddxddddddd          S (  Nr.   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fetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionsfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchWithdrawals)reduceMargin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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)r4   fundingr7   
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   
timeframes
exceptionsoptionscommonCurrencies)deep_extendsuperr.   describer+   parse_numberr(   r   r)   r   r   r#   r"   r%   r    r$   r&   r*   )self	__class__s    Q/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/hitbtc.pyr  zhitbtc.describe   s   fd 3 3 < < > > LLL $L 	L
 %L $L TL "4L tL  L 'L tL &tL (L 'L  (!L" "4#L L$ T%L&  'L( )L* +D+L, )$-L. $T/L0 '1L2 (3L4 "45L6 &t7L8  9L: +D;L< *:=L> +D?L@ &tALB #DCLD *4EL L LF $TGLH "4ILJ *5KLL +EMLN  OLP %dQLR $USLT ":ULV #DWLX +EYLZ [L\ !$]L^ &u_L`  aLb dcLd $TeLf +EgL L Lh !$iLj "4kLl dmLn !$oLp "4qLr usLt #DuLv  wLx !$yLz )${L| t}L~ L@ tALB "4CLD #DELF $ZGLH #DIL LJ !%#"!&#(  WL L LZ '}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8!..x88 "..s33T5F5Fx5P5PQ!..t44d6G6G6Q6QR!..u55t7H7H7R7RS!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I(8S8ST!..w779J9J89T9TU!..w779J9J39O9OP!..w779J9J99U9UV!..x88$:K:KI:V:VW" "..s33T5F5Fx5P5PQ!..t44d6G6G6Q6QR!..u55t7H7H7R7RS!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I(8S8ST!..w779J9J89T9TU!..w779J9J89T9TU!..w779J9J89T9TU!..x88$:K:KH:U:UV"  !F  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 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 9 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 9h +--**q9 9 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 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 y 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 y 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 y 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 yn 5oy yv #'+# # !%KH HR!!u! z! |	!
 |! {! z! x! {! t! i! |! z! w! !  !!" v#!$ #)! ! !Cw	A
 w	A
 w	 w	 w		    c                 *    |                                  S N)milliseconds)r  s    r  noncezhitbtc.nonce  s      """r  returnc                    |                      |          }g }t          |                                          }t          dt	          |                    D ]}||         }|                    d          r!|                     ||          }|                     |d          }|                     |d          }	|dk    }
|dk    }| 	                    |dd          }|o|}|	d	u}|
o| }d}| 
                    |d
d          }|                     |d          }|                     |d          }|                     |          }|                     |          }|                     |          }d	}d	}|dz   |z   }d}d	}d	}d	}|
rP|                     d          }|}|                     |          }|d	uo||k    }| }|dz   |z   }|r|dz   |	z   }d}n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)|                     t          j        ||                    d	d)d*d	|d+           |S ),a  
        retrieves data on all markets for hitbtc
        :see: 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futuresr4   margin_tradingFNbase_currency
underlyingquote_currencyfee_currency/1:-r7   r6   quantity_increment	tick_sizer  symbolbasequotesettlebaseIdquoteIdsettleIdr5   r8   activeTcontractlinear	take_rate	make_rate)amountpricemax_initial_leverager   minmax)leverager  r  cost)inverser   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_numberr,   
string_mul)"r  paramsresponseresultidsir  market
marketTyper  r  r4   marginTradingr5   r7   r6   r8   r  r  feeCurrencyIdr  r  r  r  r  r  r  r  r  r  	lotString
stepStringlotsteps"                                     r  fetch_marketszhitbtc.fetch_markets  sY    --f55> 8==??##q#c((## ^	 ^	AQB{{6"" __Xr22F))&&99J&&vx88F"i/H&(D NN63CUKKM+mFD(F+VDF''NNF&&v/?@@G ,,V^DDM**622D++G44E11-@@KHFCZ%'FDLFG "#0055(00:: ,C5F?$*#. "#c\F2F#DD!D((1EFFI))&+>>J##I..C$$Z0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5#//8NPQRR! !
  ## 
  $# 
  $001CIz1Z1Z[[#  $  e3 3 3 3 3 3 3h r  c                    |                      |          }i }t          |                                          }t          dt	          |                    D ]}||         }|                     |          }||         }|                     |d          }	|                     |d          }
|                     |dd          }|                     |dd          }|                     |dd          }|o|o|}| 	                    |dg           }i }d	}d	}d	}t          dt	          |                    D ]}||         }| 
                    |d
d          }|                     |          }|                     |d          }|                     |d          }|                     |dd          }|                     |dd          }|o|}|r|sd}n|sd}|r|sd}n|sd}||||||||dd	d	did	||<   t          |                                          }t	          |          }||||
|	|||||dk    r|nd	dd	d	did||<   |S )a  
        fetches all available currencies on an exchange
        :see: https://api.hitbtc.com/#currencies
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   	full_nameprecision_transferpayin_enabledFpayout_enabledtransfer_enabledrf  Nprotocolnetwork
payout_feeprecision_payoutTr~   r  )	r  r  r  feer  depositr~   r  r  r   r  )r  coder  r  r  r  r  r~   rf  r  r  )publicGetPublicCurrencyr  r  r  r  r  r  r  r  r  r  safe_network)r  r  r  r  
currenciesr  
currencyIdr  entryr  r  payinEnabledpayoutEnabledtransferEnabledr  rawNetworksrf  r  depositEnabledwithdrawEnabledj
rawNetwork	networkIdr  networkPrecisionpayinEnabledNetworkpayoutEnabledNetworkactiveNetworknetworksKeysnetworksLengths                                 r  fetch_currencieszhitbtc.fetch_currencies%  s    //774 (--//**
q#j//** C	 C	A#AJ**:66DZ(E##E;77D((0DEEI>>%%HHL NN52BEJJM"nnU4FNNO!GmGF//%R@@KHC!N"O1c+..//    (^
 ..z:yQQ	++I66&&z<@@#'#3#3J@R#S#S &*nnUOU&S&S#'+~~e=Mu'U'U$ 3 L8L& +~ +%)NN, +%*N' , ,&*OO- ,&+O&#&+2 4!1"#'#'% %% %!!   00L ..N & )+$-22ss##  F4LL$ r  c                 2    |d S |                                 S r  )upper)r  r  s     r  r  zhitbtc.safe_network  s    4??$$$r  r  c                 D   |                                   |                     |          }d|d         i}|                     |d          }|T|dk    rN|                     | j        d          }|                     ||          }|||d<   |                     |d          }|                     |                     ||                    }|                     |d          }	| 	                    |	          |                     |d          |                     |d          d|d	S )
a  
        create a currency deposit address
        :see: 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   rf  address
payment_id)r  r  tagr  r  )
load_marketsr  safe_string_upperr  r  r  omitprivatePostWalletCryptoAddressextendr  )
r  r  r  r  requestr  rf  parsedNetworkr  r  s
             r  create_deposit_addresszhitbtc.create_deposit_address  s-    	==&&
 ((;;dfnnt|Z@@H ,,Xw??M(&3
#YYvy11F66t{{7F7S7STT %%h
;;
//
;;'')<<##Hl;;
 
 	
r  c                 ~   |                                   |                     |          }d|d         i}|                     |d          }|T|dk    rN|                     | j        d          }|                     ||          }|||d<   |                     |d          }|                     |                     ||                    }|                     |d          }	|                     |	d          }
|                     |	d          }|                     |	d	          }| 	                    |          }||
|||dd
S )az  
        fetch the deposit address for a currency associated with self account
        :see: 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>`
        r  r  r  Nr   rf  r   r  r  )r  r  r  r  r  r  )
r  r  r  r  r  r  r  privateGetWalletCryptoAddressr  r  )r  r  r  r  r  r  rf  r  r  firstAddressr  r  r  
parsedCodes                 r  fetch_deposit_addresszhitbtc.fetch_deposit_address  sR    	==&&
 ((;;dfnnt|Z@@H ,,Xw??M(&3
#YYvy11F55dkk'66R6RSS x33""<;;%%lJ??
|\::,,Z88
"
 
 	
r  c                 p   d|i}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )Nr  r   r  	availablefreereservedused)r  r  r  r  accountsafe_balance)r  r  r  r  r  r  r  r'  s           r  parse_balancezhitbtc.parse_balance  s    (#q#h--(( 	# 	#AQKE))%<<J**:66DllnnG"..ukBBGFO"..ujAAGFO"F4LL  (((r  c                 6   |                      |dd          }|                     |dg          }|                     | j        di           }|                     |||          }d}|dk    r|                     |          }n|dk    r|                     |          }nj|dk    r|                     |          }nNt          |	                                          }t          | j        dz   d                    |          z             |                     |          S )	a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://api.hitbtc.com/#wallet-balance
        :see: https://api.hitbtc.com/#get-spot-trading-balance
        :see: 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  r4   rg  Nr`  ra  z. fetchBalance() type parameter must be one of , )safe_string_lowerr  r  r  r  privateGetWalletBalanceprivateGetSpotBalanceprivateGetFuturesBalancer  r  r"   r  joinr)  )r  r  r  rg  r'  r  r  s          r  fetch_balancezhitbtc.fetch_balance  s    %%fff==6F8,,7GLL"">4>>h33F;;HH11&99HH%%44V<<HH++--..DTW'WWZ^ZcZcdhZiZiijjj !!(+++r  r  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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  sr     	V$$fTl
 33DKK4P4PQQ   6222r  Nsymbolsc                 L   |                                   |                     |          }i }|/|                     |          }d                    |          }||d<   |                     |                     ||                    }i }t          |                                          }t          dt          |                    D ]H}	||	         }
| 
                    |
          }|d         }||
         }|                     ||          ||<   I|                     |d|          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: 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>`
        N,r7  r   r  )r  market_symbols
market_idsr0  publicGetPublicTickerr  r  r  r  r  safe_marketr4  filter_by_array_tickers)r  r7  r  r  	marketIds	delimitedr  r  r  r  marketIdr  r  r  s                 r  fetch_tickerszhitbtc.fetch_tickers(  s    	%%g..00I++I!*GI--dkk'6.J.JKK  HMMOO$$q#d))$$ 	> 	>AAwH%%h//FH%FX&E!..uf==F6NN++FHgFFFr  r  c                 x   |                      |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|          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  tickerr  rD  r  rU  rV  rG  rH  s	            r  r4  zhitbtc.parse_tickerQ  s    NN6+#677	!!$//%%fh77
&&v~>>//// !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r  sincelimitc                    |                                   d}i }|t          |d          |d<   |||d<   d}|J|                     |          }|d         |d<   |                     |                     ||                    }n)|                     |                     ||                    }||                     ||          S g }t          |                                          }	t          dt          |	                    D ]S}
|	|
         }|                     |          }||         }|                     ||          }|                     ||          }T|S )a
  
        get the list of most recent trades for a particular symbol
        :see: 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>`
        N  r]  fromr  r  r   )r  r  r  publicGetPublicTradesSymbolr  publicGetPublicTradesparse_tradesr  r  r  r  array_concat)r  r  r\  r]  r  r  r  r  tradesr?  r  rA  marketInner	rawTradesparseds                  r  fetch_tradeszhitbtc.fetch_trades|  sa    	"5$//GG#GFO[[((F &tGH77GV8T8TUUHH11$++gv2N2NOOH$$Xv666))	q#i..)) 	7 	7A |H++h//K *I&&y+>>F&&vv66FFr  c                 
   |                                   d}i }| |                     |          }|d         |d<   |||d<   |||d<   d}d}d}	|                     d||          \  }}|                     d|          \  }}|                     |ddg          }|*|                     |                     ||                    }	n|d	k    r*|                     |                     ||                    }	nw|d
k    r*|                     |                     ||                    }	nG|dk    r*|                     |                     ||                    }	nt          | j
        dz             |                     |	|||          S )a	  
        fetch all trades made by the user
        :see: https://api.hitbtc.com/#spot-trades-history
        :see: https://api.hitbtc.com/#futures-trades-history
        :see: 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`  rc   
marginModer5   r4   r6   z- fetchMyTrades() not support self market typer  r  handle_market_type_and_paramshandle_margin_mode_and_paramsr  privateGetMarginHistoryTrader  privateGetSpotHistoryTradeprivateGetFuturesHistoryTrader'   r  rc  
r  r  r\  r]  r  r  r  r  rk  r  s
             r  fetch_my_tradeszhitbtc.fetch_my_trades  s    	[[((F &tGH$GG#GFO

!??QWY_``
F!??QWXX
F6L(#;<<!88Wf9U9UVVHHV##::4;;wPV;W;WXXv%%==dkk'SY>Z>Z[[x''<<T[[RX=Y=YZZ"47-\#\]]]  65%@@@r  c                    |                      |d                   }|                     |d          }|                     ||          }|d         }d }|                     |d          }|                     |d          }d }	||rdnd}	nd}	|G|                     |di           }
|                     |
d          }|                     |          }||d}|                     |d	d
          }|                     |d          }|                     |dd          }|                     |d          }|                     |d          }|                     |||||                     |          |d ||	||d |d|          S )NrD  r  r  r   r   r  r  )r  r  clientOrderIdclient_order_idr  quantityqtysider  )r  r  orderrD  rI  r  r  ry  takerOrMakerr  r  r  r  )rW  r  r=  r  r  r  
safe_traderZ  )r  trader  rD  rA  r  r  feeCostStringr   r{  r  r  feeCurrencyCodeorderIdpriceStringamountStringry  r  s                     r  parse_tradezhitbtc.parse_trade  s   r NN5#566	##E844!!(F33!((66w//&+877LL"L$??66266D**4@@K"55kBBO%+ C $$UO=NOO&&ug66))%UCCv..eT**"Y//( " 
  
   	r  c                 @   |                                   d|i}d }| |                     |          }|d         |d<   ||                     |          |d<   |||d<   |                     |                     ||                    }|                     |||||          S )Ntypesr  r  r`  r]  )r  r  rZ  privateGetWalletTransactionsr  parse_transactions)	r  r  r  r\  r]  r  r  r  r  s	            r  fetch_transactions_helperz hitbtc.fetch_transactions_helper0  s    U
 }}T**H$,TNGL!"ll511GFO$GG44T[[&5Q5QRR2 &&x5%PPPr  c                 <    dddd}|                      |||          S )Npendingfailedok)PENDINGFAILEDSUCCESSr  r  statusstatusess      r  parse_transaction_statuszhitbtc.parse_transaction_statusX  s1     
 

 &&999r  c                 :    ddd}|                      |||          S )Nr  
withdrawal)DEPOSITWITHDRAWr  )r  r  r  s      r  parse_transaction_typezhitbtc.parse_transaction_type`  s.     $
 
 tT222r  r  c                 0   |                      |dd          }|                     |                     |d                    }|                     |                     |d                    }|                     |                     |d                    }|                     |                     |d                    }|                     |di           }|                     |d          }	|                     |	          }
|                     |d	          }|                     |d
          }|}|                     |d          }|}|                     |d          }|                     |d          }|                     |d          }|                     |d          }|dk    }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S ) Noperation_idr  
created_at
updated_atr  r  nativer  hashr  r  sendersr   r  subtypeOFFCHAIN)r  r  rater  r  r  txidr  rD  rI  addressFrom	addressTor  tagFromtagToupdated)commentinternalr  )	r  rW  r  r  r  r  r  r  rZ  )r  transactionr  r  rD  r  r  r  r  r  r  txhashr  r  r  r  senderr  r  subTyper  r  feeCosts                          r  parse_transactionzhitbtc.parse_transactiong  s   B ^TBBNN4#3#3K#N#NOO	..!1!1+|!L!LMM**4+;+;K+P+PQQ..t/?/?X/V/VWWh;;%%fj99
&&z22!!&&11""6955	v|4433&&vq11!!&(33"";	::j( 
 

 ""6511"C
O!CK
K
"
 F
 D	

 
 t
 f
 f
 
 Y//
 w
 ;
 
 3
 t
  U!
" w#
$  )
 
 
 	
r  c                 4    |                      d||||          S )ac  
        fetch history of deposits and withdrawals
        :see: 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_withdrawals  s"     --.@$uV\]]]r  c                 4    |                      d||||          S )a  
        fetch all deposits made to an account
        :see: 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_deposits  s      --iueVTTTr  c                 4    |                      d||||          S )a  
        fetch all withdrawals made from an account
        :see: 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_withdrawals  s      --j$ufUUUr  c                 V   |                                   i }|-|                     |          }d                    |          |d<   |||d<   |                     |                     ||                    }i }t          |                                          }t          dt          |                    D ]r}	||	         }
||
         }| 	                    |
          }| 
                    |                     |d                    }|                     ||
         ||dd          ||<   s|S )	aa  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data for multiple markets
        :see: https://api.hitbtc.com/#order-books
        :param str[]|None 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
        Nr9  r7  depthr   rD  rL  rN  )r  r;  r0  publicGetPublicOrderbookr  r  r  r  r  rX  rW  r  parse_order_book)r  r7  r]  r  r  marketIdsInnerr  r  r?  r  rA  	orderbookr  rD  s                 r  fetch_order_bookszhitbtc.fetch_order_books  s(    	!__W55N!$.!9!9GI$GG00Wf1M1MNN))	q#i..)) 	h 	hA |H *I%%h//Ft'7'7	;'O'OPPI!228H3EvyZ_afggF6NNr  c                 L   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |                     |d                    }|                     |||dd          S )a%  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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  Nr  rD  rL  rN  )r  r  publicGetPublicOrderbookSymbolr  rW  r  r  )r  r  r]  r  r  r  r  rD  s           r  fetch_order_bookzhitbtc.fetch_order_book  s     	V$$fTl
 $GG66t{{7F7S7STTNN4#3#3Hk#J#JKK	$$Xvy%OOOr  c                     |                      |d          }|                      |d          }|                     |d          }|                     ||          }||||d d dS )Nr  r  r  )r  r  r   r   r   r   )r  r  rX  )r  r  r  r   r   rA  r  s          r  parse_trading_feezhitbtc.parse_trading_fee  sy       k22  k22##C22!!(F33
 
 	
r  c                    |                                   |                     |          }d|d         i}d}|d         dk    r*|                     |                     ||                    }nM|d         dk    r*|                     |                     ||                    }nt          | j        dz             |                     ||          S )a  
        fetch the trading fees for a market
        :see: https://api.hitbtc.com/#get-trading-commission
        :see: 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  r4   r6   z/ fetchTradingFee() not support self market type)r  r  privateGetSpotFeeSymbolr  privateGetFuturesFeeSymbolr'   r  r  r5  s         r  fetch_trading_feezhitbtc.fetch_trading_fee#  s     	V$$fTl
 &>V##33DKK4P4PQQHHF^v%%66t{{7F7S7STTHHtw)ZZ[[[ %%h777r  c                    |                                   |                     dd|          \  }}d}|dk    r|                     |          }n3|dk    r|                     |          }nt	          | j        dz             i }t          dt          |                    D ]*}|                     ||                   }|d         }|||<   +|S )a  
        fetch the trading fees for multiple markets
        :see: https://api.hitbtc.com/#get-all-trading-commissions
        :see: 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
        ru   Nr4   r6   z0 fetchTradingFees() not support self market typer   r  )	r  rm  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44HH6!!0077HHtw)[[\\\ q#h--(( 	! 	!A((!55C]F F6NNr  r   c           	         |                                   d}|                     |dd          \  }}|r|                     d|||||d          S |                     |          }|d         |                     | j        ||          d}||                     |          |d<   |                     d	||          \  }}|t          |d          |d
<   |                     |d          }	| 	                    |d          }d}
|	dk    r*| 
                    |                     ||                    }
n|	dk    r*|                     |                     ||                    }
nY|	dk    r*|                     |                     ||                    }
n)|                     |                     ||                    }
|                     |
||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://api.hitbtc.com/#candles
        :see: https://api.hitbtc.com/#futures-index-price-candles
        :see: https://api.hitbtc.com/#futures-mark-price-candles
        :see: 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
        Frd   paginater_  r  )r  periodNr`  tillr]  r  markindexpremiumIndex)r  handle_option_and_params"fetch_paginated_call_deterministicr  r  r  rZ  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_ohlcva  s     	88zZZ& 	x::<QVX]_hjprvwwwV$$Tl&&t	9MM
 
 "ll511GFO2267FKK"5$//GG  1167++F??HHU\^dIeIeffHHgII$++V]_eJfJfggHHn$$KKDKKX_agLhLhiiHH88Wf9U9UVVH8   69eUKKKr  c           	      (   |                      |                     |d                    |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )NrD  rG  r  r  rQ  rE  )rW  r  r  )r  ohlcvr  s      r  parse_ohlcvzhitbtc.parse_ohlcv  s    2 NN4++E;??@@UF++UE**UE**UG,,UH--
 	
r  c                 d   |                                   d}i }| |                     |          }|d         |d<   ||                     |          |d<   |||d<   d}d}|                     d||          \  }}|                     d|          \  }}|                     |ddg          }d}	|*|                     |                     ||                    }	n|d	k    r*|                     |                     ||                    }	nw|d
k    r*| 	                    |                     ||                    }	nG|dk    r*|                     |                     ||                    }	nt          | j        dz             |                     |	|||          }
|                     |
dddgd          S )aG  
        fetches information on multiple closed orders made by the user
        :see: https://api.hitbtc.com/#spot-orders-history
        :see: https://api.hitbtc.com/#futures-orders-history
        :see: 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]  rI   rk  r5   r4   r6   z1 fetchClosedOrders() not support self market typer  closedcanceledF)r  r  rZ  rm  rn  r  privateGetMarginHistoryOrderr  privateGetSpotHistoryOrderprivateGetFuturesHistoryOrderr'   r  parse_ordersfilter_by_array)r  r  r\  r]  r  r  r  r  rk  r  rh  s              r  fetch_closed_orderszhitbtc.fetch_closed_orders  s    	[[((F &tGH"ll511GFO$GG

!??@SU[]cdd
F!??@SU[\\
F6L(#;<<!88Wf9U9UVVHHV##::4;;wPV;W;WXXv%%==dkk'SY>Z>Z[[x''<<T[[RX=Y=YZZ"47-`#`aaa""8VUEBB##FHx6LeTTTr  r  c                    |                                   d}||                     |          }d|i}d}d}|                     d||          \  }}|                     d|          \  }}|                     |ddg          }d}|*|                     |                     ||                    }n|dk    r*|                     |                     ||                    }nw|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j
        dz             |                     |d	          }	|                     |	|          S )
a  
        fetches information on an order made by the user
        :see: https://api.hitbtc.com/#spot-orders-history
        :see: https://api.hitbtc.com/#futures-orders-history
        :see: https://api.hitbtc.com/#margin-orders-history
        :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>`
        Nrv  ri   rk  r5   r4   r6   z* fetchOrder() not support self market typer   )r  r  rm  rn  r  r  r  r  r  r'   r  	safe_dictparse_order)
r  r  r  r  r  r  r  rk  r  rz  s
             r  fetch_orderzhitbtc.fetch_order  s    	[[((Fr
 

!??fV\]]
F!??fUU
F6L(#;<<!88Wf9U9UVVHHV##::4;;wPV;W;WXXv%%==dkk'SY>Z>Z[[x''<<T[[RX=Y=YZZ"47-Y#YZZZ( x++v...r  c                    |                                   d}||                     |          }d|i}d}d}	|                     d||          \  }}|                     d|          \  }	}|                     |ddg          }d}
|	*|                     |                     ||                    }
n|dk    r*|                     |                     ||                    }
nw|dk    r*|                     |                     ||                    }
nG|dk    r*|                     |                     ||                    }
nt          | j
        dz             |                     |
|||          S )	a)  
        fetch all the trades made from a single order
        :see: https://api.hitbtc.com/#spot-trades-history
        :see: https://api.hitbtc.com/#futures-trades-history
        :see: 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_idrm   rk  r5   r4   r6   z0 fetchOrderTrades() not support self market typerl  )r  r  r  r\  r]  r  r  r  r  rk  r  s              r  fetch_order_tradeszhitbtc.fetch_order_trades/  s    	[[((F
 

!??@RTZ\bcc
F!??@RTZ[[
F6L(#;<<!88Wf9U9UVVHHV##::4;;wPV;W;WXXv%%==dkk'SY>Z>Z[[x''<<T[[RX=Y=YZZ"47-_#_```N   65%@@@r  c                    |                                   d}i }| |                     |          }|d         |d<   d}d}|                     d||          \  }}|                     d|          \  }}|                     |ddg          }d}	|*|                     |                     ||                    }	n|dk    r*|                     |                     ||                    }	nw|dk    r*|                     |                     ||                    }	nG|dk    r*|                     |                     ||                    }	nt          | j
        d	z             |                     |	|||          S )
a-  
        fetch all unfilled currently open orders
        :see: https://api.hitbtc.com/#get-all-active-spot-orders
        :see: https://api.hitbtc.com/#get-active-futures-orders
        :see: 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  rh   rk  r5   r4   r6   z/ fetchOpenOrders() not support self market type)r  r  rm  rn  r  privateGetMarginOrderr  privateGetSpotOrderprivateGetFuturesOrderr'   r  r  rr  s
             r  fetch_open_orderszhitbtc.fetch_open_orders~  s    	[[((F &tGH

!??@QSY[abb
F!??@QSYZZ
F6L(#;<<!11$++gv2N2NOOHHV##33DKK4P4PQQv%%66t{{7F7S7STTx''55dkk'66R6RSS"47-^#^___(   65%@@@r  c                    |                                   d}||                     |          }d|i}d}d}|                     d||          \  }}|                     d|          \  }}|                     |ddg          }d}|*|                     |                     ||                    }n|dk    r*|                     |                     ||                    }nw|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j
        dz             |                     ||          S )	a  
        fetch an open order by it's id
        :see: https://api.hitbtc.com/#get-active-spot-order
        :see: https://api.hitbtc.com/#get-active-futures-order
        :see: 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>`
        Nrv  rg   rk  r5   r4   r6   z. fetchOpenOrder() not support self market type)r  r  rm  rn  r  "privateGetMarginOrderClientOrderIdr   privateGetSpotOrderClientOrderId#privateGetFuturesOrderClientOrderIdr'   r  r  	r  r  r  r  r  r  r  rk  r  s	            r  fetch_open_orderzhitbtc.fetch_open_order  s    	[[((Fr
 

!??@PRXZ`aa
F!??@PRXYY
F6L(#;<<!>>t{{7TZ?[?[\\HHV##@@WV\A]A]^^v%%CCDKKPWY_D`D`aax''BB4;;wX^C_C_``"47-]#]^^^&111r  c                    |                                   d}i }| |                     |          }|d         |d<   d}d}|                     d||          \  }}|                     d|          \  }}|                     |ddg          }d}|*|                     |                     ||                    }n|dk    r*|                     |                     ||                    }nw|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j
        d	z             |                     ||          S )
a  
        cancel all open orders
        :see: https://api.hitbtc.com/#cancel-all-spot-orders
        :see: https://api.hitbtc.com/#cancel-futures-orders
        :see: 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  r:   rk  r5   r4   r6   z/ cancelAllOrders() not support self market type)r  r  rm  rn  r  privateDeleteMarginOrderr  privateDeleteSpotOrderprivateDeleteFuturesOrderr'   r  r  r  r  r  r  r  r  rk  r  s           r  cancel_all_orderszhitbtc.cancel_all_orders  s    	[[((F &tGH

!??@QSY[abb
F!??@QSYZZ
F6L(#;<<!44T[[&5Q5QRRHHV##66t{{7F7S7STTv%%99$++gv:V:VWWx''88Wf9U9UVV"47-^#^___  6222r  c                    |                                   d}d|i}||                     |          }d}d}|                     d||          \  }}|                     d|          \  }}|                     |ddg          }d}|*|                     |                     ||                    }n|dk    r*|                     |                     ||                    }nw|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j
        dz             |                     ||          S )	a  
        cancels an open order
        :see: https://api.hitbtc.com/#cancel-spot-order
        :see: https://api.hitbtc.com/#cancel-futures-order
        :see: 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>`
        Nrv  r;   rk  r5   r4   r6   z+ cancelOrder() not support self market type)r  r  rm  rn  r  %privateDeleteMarginOrderClientOrderIdr  #privateDeleteSpotOrderClientOrderId&privateDeleteFuturesOrderClientOrderIdr'   r  r  r  s	            r  cancel_orderzhitbtc.cancel_order  s    	r
 [[((F

!??vW]^^
F!??vVV
F6L(#;<<!AA$++gW]B^B^__HHV##CCDKKPWY_D`D`aav%%FFt{{SZ\bGcGcddx''EEdkkRY[aFbFbcc"47-Z#Z[[[&111r  r  ry  r  r  c                 ~   |                                   d }||                     ||          d}	|dk    s|dk    r2|t          | j        dz             |                     ||          |	d<   ||                     |          }d }
d }|                     d||          \  }
}|                     d|          \  }}|                     |ddg          }d }|*| 	                    | 
                    |	|                    }n|
d	k    r*|                     | 
                    |	|                    }nw|
d
k    r*|                     | 
                    |	|                    }nG|
dk    r*| 	                    | 
                    |	|                    }nt          | j        dz             |                     ||          S )N)rv  rw  r]  	stopLimitz' editOrder() limit order requires pricer  rD   rk  r5   r4   r6   z) editOrder() not support self market type)r  amount_to_precisionr   r  price_to_precisionr  rm  rn  r  $privatePatchMarginOrderClientOrderIdr  "privatePatchSpotOrderClientOrderId%privatePatchFuturesOrderClientOrderIdr'   r  )r  r  r  r  ry  r  r  r  r  r  r  rk  r  s                r  
edit_orderzhitbtc.edit_order+  s   !00@@
 
 GOO!4!4}#DG.W$WXXX#66vuEEGG[[((F

!??VU[\\
F!??VTT
F6L(#;<<!@@WV\A]A]^^HHV##BB4;;wX^C_C_``v%%EEdkkRY[aFbFbccx''DDT[[QXZ`EaEabb"47-X#XYYY&111r  c           
      J   |                                   |                     |          }d}d}	|                     d||          \  }	}d}
|                     d|          \  }
}|                     ||	|||||
|          \  }}d}|	dk    r*|                     |                     ||                    }n[|	dk    s|
*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    ||          S )a  
        create a trade order
        :see: https://api.hitbtc.com/#create-new-spot-order
        :see: https://api.hitbtc.com/#create-margin-order
        :see: 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 fullfilled, 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>`
        Nr>   r6   r5   )
r  r  rm  rn  create_order_requestprivatePostFuturesOrderr  privatePostMarginOrderprivatePostSpotOrderr  )r  r  r  ry  r  r  r  r  r  r  rk  r  s               r  create_orderzhitbtc.create_orderK  s3   & 	V$$
!??vW]^^
F
!??vVV
F33FJdTZ\acmouvv33DKK4P4PQQHHH$$**@224;;w3O3OPPHH00Wf1M1MNNH&111r  r  rk  c	                    |dk    }	|                      |d          }
|                     |d          }|                     |g d          }|                     |dk    d |          }|||                     |d         |          |d         d}|
;|d	         d
k    r/|d	         dk    r#t          | j        dz   |d	         z   dz             |
du r|
|d<   |rd|d<   |||d<   |	s|dk    s|dk    r8|t          | j        dz             |                     |d         |          |d<   |dk    r/|                     |d          }|t          | j        dz             |3|                     |d         |          |d<   |	rd|d	<   n;|dk    rd|d	<   n/|dk    s|dk    s|dk    s|dk    rt          | j        dz             | 	                    |g d          }|d
k    r	|d}||d<   ||gS ) Nr]  
reduceOnlytimeInForce)triggerPrice	stopPrice
stop_pricer  r  r  )r  ry  rw  r  r  r6   r5   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  GTDexpire_timez@ createOrder() requires an expire_time parameter for a GTD orderr  
stopMarkettakeProfitMarketzR createOrder() requires a stopPrice 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   r  r  )r  r  r  r  ry  r  r  rk  r  isLimitr  r  r  
isPostOnlyr  
expireTimes                   r  r  zhitbtc.create_order_requesto  s   7?__V\::
&&v}==))&2]2]2]^^&&tx'7vFF
001A6JJTl	
 
" !v&((vf~/I/I"47-_#_bhiobp#p  t@  $@  A  A  A%/GM" 	(#'GK "'2GO$ 	Pt{**8I0I0I}#DG.i$ijjj#66vh7GOOGG5  ))&-@@J!#DG.p$pqqq#$($;$;F8<Ll$[$[GL! /"-!!".k!!t|';';IZAZAZ`dhz`z`z*~ ~6#w#w#wxx!$
%/GM"  r  c                 B    ddddddd}|                      |||          S )NrG  r  r  r  )new	suspendedpartiallyFilledfilledr  expiredr  r  s      r  parse_order_statuszhitbtc.parse_order_status  s:    %"
 
 &&999r  c                 T   |                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }	|                     |	          }
|                      |d          }d }||	k    r|                     |          }|                      |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	|          S )Nrv  ry  r  rw  r  price_averager  r  quantity_cumulativer  r  r  r  re  r  r  r  ru  rD  rI  lastTradeTimestamplastUpdateTimestampr  r  r%  r  r  r1  	remaining)	r  r  rT  re  r  r  r  takeProfitPricestopLossPrice)r  rW  r3  r=  r  
safe_orderrZ  )r  rz  r  r  ry  r  r  r  rT  r  rD  r  r7  r1  r  rA  r  r%  r  rg  r  s                        r  r  zhitbtc.parse_order  s   D e%677 v..v..!!%44  00""5/::""5,77NN7++	""5,77!g!%!8!8!!%)>??(()9)9%)J)JKK##E844!!(F33!??5+66&&uo>>OOE844	$$UL99	  
E 
" 
 R 
 	 

 Y// 
 !"4 
 "#5 
 f 
 U 
 f 
 D 
 D 
 ; 
  
 $//%?? 
  f! 
" # 
$ "%#!5 
  
  
6 7  	r  c                    |                                   d}|0|                     |          }|                     |d                   }d}|                     d||          \  }}d}|dk    r|                     |          }n3|dk    r|                     |          }nt          | j        dz             |                     |dg           }| 	                    ||d          S )	a  
        fetches margin mode of the user
        :see: https://api.hitbtc.com/#get-margin-position-parameters
        :see: https://api.hitbtc.com/#get-futures-position-parameters
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `margin mode structures <https://docs.ccxt.com/#/?id=margin-mode-structure>`
        Nr   r]   r5   r6   z; fetchMarginModes() supports swap contracts and margin onlyconfigr  )
r  r:  r  rm  privateGetMarginConfigprivateGetFuturesConfigr#   r  	safe_listparse_margin_modes)r  r7  r  r  r  r  r>  s          r  fetch_margin_modeszhitbtc.fetch_margin_modes)	  s     	))'22G[[,,F
!??@QSY[abb
F!!226::HH$ 6!!33F;;HH& DG&ccddd(B77&&vwAAAr  c                     |                      |d          }||                     ||          |                     |d          dS )Nr  r'  )r  r  rk  )r  rX  r,  )r  rk  r  rA  s       r  parse_margin_modezhitbtc.parse_margin_modee	  sO    ##J99&&x8800]KK
 
 	
r  fromAccount	toAccountc                 6   |                                   |                     |          }|                     ||          }|                     | j        di           }|                                }|                                }|                     |||          }	|                     |||          }
|	|
k    rt          | j        dz             |d         ||	|
d}| 	                    | 
                    ||                    }|                     ||          S )a  
        transfer currency internally between wallets on the same account
        :see: 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>`
        rg  zJ transfer() fromAccount and toAccount arguments cannot be the same accountr  )r  r  sourcedestination)r  r  currency_to_precisionr  r  lowerr  r"   r  privatePostWalletTransferr  parse_transfer)r  r  r  rF  rG  r  r  requestAmountrg  fromIdtoIdr  r  s                r  r}   zhitbtc.transferm	  s    	==&&224@@7GLL!''))OO%%	!!.+{KK	9EET>>TW'ssttt #	
 
 11$++gv2N2NOO ""8X666r  c           
      j    |                      |d          d d |                     d |          d d d d |d	S )Nr   )	r  rD  rI  r  r  rF  rG  r  r  )r  r  )r  r}   r  s      r  rN  zhitbtc.parse_transfer	  sN     ""8Q////h??

 

 
	
r  c                    |                                   |dk    rt          | j        dz             |                     | j        di           }|                                }|                                }|                     ||          }|                     ||          }||k    rt          | j        dz             ||Nt          |	                                          }t          | j        dz   d                    |          z             |||                     ||          d}|                     |                     ||                    }	d|	iS )	Nr   z6 convertCurrencyNetwork() only supports USDT currentlyrf  z8 convertCurrencyNetwork() fromNetwork cannot be the samezm convertCurrencyNetwork() requires a fromNetwork parameter and a toNetwork parameter, supported networks are r+  )from_currencyto_currencyr  r  )r  r   r  r  r  r  r  r"   r  r  r!   r0  rK  privatePostWalletConvertr  )
r  r  r  fromNetwork	toNetworkr  rf  r  r  r  s
             r  convert_currency_networkzhitbtc.convert_currency_network	  s   6>>*b bccc??4<R@@!''))OO%%	&&x==$$Xy99	)##TW'aabbbY%6((D#DG  /^  %^  ae  aj  aj  ko  ap  ap  %p  q  q  q($00v>>
 

 00Wf1M1MNN H
 	
r  c                    |                      ||          \  }}|                                  |                     |           |                     |          }|d         ||d}|||d<   |                     | j        di           }|                     |d          }	|	9|dk    r3|                     ||	          }
|
|
|d<   |                     |d          }|                     | j        d	i           }| 	                    |d
d          }|rd|d<   | 
                    |                     ||                    }|                     ||          S )a  
        make a withdrawal
        :see: 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  )r  r  r  Nr  rf  r  r   network_coder~   rc  FTinclude_fee)handle_withdraw_tag_and_paramsr  check_addressr  r  r  r  r  r  r  privatePostWalletCryptoWithdrawr  r  )r  r  r  r  r  r  r  r  rf  r  r  withdrawOptionsrc  r  s                 r  r~   zhitbtc.withdraw	  sg    99#vFFV7###==&& 
 

 ?$'GL!??4<R@@((;;dfnn ,,Xw??M(*7'YYvy11F//$,
BGG^^O\5II
 	*%)GM"77GV8T8TUU %%h999r  c                 <   |                                   d}i }|]|                     |          }|                     |d                   }|                     |          }d                    |          |d<   d}|                     d||          \  }}|dk    rt          | j        dz   |z   dz             |                     | 	                    ||                    }t          |                                          }i }	t          dt          |                    D ]f}
|                     ||
          }|                     ||          }|                     |          }|d	         }|                     ||          }||	|<   g|                     |	d	|          S )
a  
        fetches funding rates for multiple markets
        :see: 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: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        Nr   r9  r7  rV   r6   z& fetchFundingRates() does not support z marketsr  )r  r:  r  r;  r0  rm  r'   r  publicGetPublicFuturesInfor  r  r  r  r  r  r  parse_funding_rater  )r  r7  r  r  r  queryMarketIdsr  r  r?  fundingRatesr  rA  rawFundingRaterf  r  fundingRates                   r  fetch_funding_rateszhitbtc.fetch_funding_rates	  s    	))'22G[[,,F!__W55N!$.!9!9GI99:MvW]^^f6>>tw)QQTXX[eefff224;;w3O3OPP$ ))	q#i..)) 	/ 	/A''	155H!__Xx@@N++h//K *F11.+NNK#.L  ##L(GDDDr  c           
          |                                   d}|                     |dd          \  }}|r|                     d|||d|d          S d}i }|                     d||          \  }}|(|                     |          }|d         }|d	         |d
<   |||d<   |||d<   |                     |                     ||                    }t          |                                          }	g }
t          dt          |	                    D ]}|	|         }|                     |          }||         }t          dt          |                    D ]}||         }|                     |d                   }|                     |d          }|                     |d          }|
                    ||||                     |          |d           |                     |
d          }|                     ||||          S )a  
        :see: 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>`
        FrU   r  8hr_  Nr  r  r  r7  r`  r]  r   funding_raterD  )r  r  rg  rD  rI  )r  r  r  r  r  $publicGetPublicFuturesHistoryFundingr  r  r  r  r  r=  rX  r  r  r  rW  sort_byfilter_by_symbol_since_limit)r  r  r\  r]  r  r  r  r  r  	contractsratesr  rA  rf  fundingRateDatar  r  symbolInnerrg  rI  sorteds                        r  fetch_funding_rate_historyz!hitbtc.fetch_funding_rate_history
  sD    	88AZ\fgg& 	@::;TV\^cejlprxz~
 2267FKK[[((FH%F!'GI#GFO$GG<<T[[RX=Y=YZZ  ))	q#i..)) 	 	A |H**844K&x0O1c/2233  '*"..{8/DEE"..unEE++E;??!)#.!%!9!9 (      e[1100NNNr  c                    |                                   i }d}d}|                     dd|          \  }}|dk    rd}|                     d|          \  }}|                     |ddg          }d}|*|                     |                     ||                    }nw|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j        dz             g }t          dt          |                    D ]0}|                    |                     ||                              1|S )	a  
        fetch all open positions
        :see: https://api.hitbtc.com/#get-futures-margin-accounts
        :see: 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>`
        Nro   r4   r6   rk  r5   z. fetchPositions() not support self market typer   )r  rm  rn  r  privateGetMarginAccountr  privateGetFuturesAccountr'   r  r  r  r  parse_position)	r  r7  r  r  r  rk  r  r  r  s	            r  fetch_positionszhitbtc.fetch_positionsa
  s{    	

!??@PRVX^__
FJ!??@PRXYY
F6L(#;<<!33DKK4P4PQQHHV##88Wf9U9UVVx''77GV8T8TUU"47-]#]^^^B q#h--(( 	< 	<AMM$--hqk::;;;;r  c                 |   |                                   |                     |          }d|d         i}d}d}|                     dd|          \  }}|                     d|          \  }}|                     |ddg          }d}|*|                     |                     ||                    }nw|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j	        dz             | 
                    ||          S )	a  
        fetch data on a single open contract trade position
        :see: https://api.hitbtc.com/#get-futures-margin-account
        :see: 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  Nrn   rk  r5   r6   z- fetchPosition() not support self market type)r  r  rm  rn  r  %privateGetMarginAccountIsolatedSymbolr  &privateGetFuturesAccountIsolatedSymbolr'   r  rx  r  s           r  fetch_positionzhitbtc.fetch_position
  sR    	V$$fTl
 

!??QUW]^^
F!??QWXX
F6L(#;<<!AA$++gW]B^B^__HHV##FFt{{SZ\bGcGcddx''EEdkkRY[aFbFbcc"47-\#\]]]B ""8V444r  c                 |   |                      |d          }|                     |d          }|                      |d          }|                     |dg           }d }d }d }	t          dt	          |                    D ]L}
||
         }|                     |d          }|                     |d          }|                     |d          }	M|                     |d	g           }d }t          dt	          |                    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 d          S )Nr  r  r  	positionsr   price_liquidationprice_entryrw  r  margin_balancer  r  r  notionalrk  
marginTypeliquidationPrice
entryPriceunrealizedPnlr   ro  r  	markPrice	lastPricery  hedgedrD  )rI  r8  maintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatior;  r:  )r  r  r  r  r  r=  safe_positionrW  )r  positionr  rk  r  rI  r  r  r  ro  r  r  r  r  rA  r  s                   r  rx  zhitbtc.parse_position
  s   B %%h77
##Hj99##Hl;;OOHk2>>	
	q#i..)) 	< 	<AaLE#//7JKK))%??J((
;;II__X|R@@

q#j//** 	C 	CAqME))%1ABBJJ##Hh77!!(F33!!! #
H#
$#
 f#
 	#

 *#
 *#
  0#
 *#
 T#
 $#
 #
 D#
 #
 #
 D#
  d!#
" 11##
$ !#'!%+/$!'+ !#9#
 #
 #
   	r  c           	          |                      |d          }|                     |d          }|                     |d         d ||                     |          ||d|          S )NrD  open_interestr  )r  openInterestAmountopenInterestValuerD  rI  r  )r  r  safe_open_interestrW  )r  interestr  rI  values        r  parse_open_interestzhitbtc.parse_open_interest9  sx      ##Hk::  ?;;&&X&"&!&11 (
 (
   	r  c                 $   |                                   |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                    }|                     ||          S )a^  
        Retrieves the open interest of a derivative trading pair
        :see: 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:
        r6   z1 fetchOpenInterest() supports swap contracts onlyr  r  )r  r  r#   r   publicGetPublicFuturesInfoSymbolr  r  r5  s         r  fetch_open_interestzhitbtc.fetch_open_interestT  s     	V$$f~ 	[DG&YYZZZfTl
 88Wf9U9UVV  ''&999r  c                 $   |                                   |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                    }|                     ||          S )aP  
        fetch the current funding rate
        :see: 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>`
        r6   z0 fetchFundingRate() supports swap contracts onlyr  r  )r  r  r#   r  r  r  rc  r5  s         r  fetch_funding_ratezhitbtc.fetch_funding_rateu  s     	V$$f~ 	ZDG&XXYYYfTl
 88Wf9U9UVV  &&x888r  c                     |                      |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 S )Nnext_funding_timerD  r  r  r  
mark_price
indexPriceindex_priceinterestRateinterest_rateestimatedSettlePricerI  rg  rk  fundingTimestampfundingDatetimenextFundingRateindicative_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)r  rX  r  rW  )r  r  r  fundingDateTimerI  s        r  rc  zhitbtc.parse_funding_rate  sz     **85HII##Hk::
H
d&&tV44
 ))(LAA
 $**8]CC	

 D,,XGG
 #D
 11
 
 4++HnEE
  ? ?
 
 t//:STT
 #D
 "4
 "4
  '!
" &t#
 	
r  c                    |                                   |                     |          }|                     |d          }|d         r|t          | j        dz             |dk    r|                     ||          }nd}|d         |d}|||d<   d }d }	|                     d||          \  }}|                     d|          \  }	}d }
|dk    r*|                     | 	                    ||                    }
nS|d	k    s|d
k    s|	dk    r*| 
                    | 	                    ||                    }
nt          | j        dz             | 	                    |                     |
|          |                     |          |d          S )Nr  r6   zD modifyMarginHelper() requires a leverage parameter for swap marketsr   r   r  )r  r  modifyMarginHelperr5   r4   isolatedz2 modifyMarginHelper() not support self market type)r  r  )r  r  r  r!   r  r  rm  rn  &privatePutFuturesAccountIsolatedSymbolr  %privatePutMarginAccountIsolatedSymbolr'   parse_margin_modificationr  )r  r  r  r  r  r  r  r  r  rk  r  s              r  modify_margin_helperzhitbtc.modify_margin_helper  s   V$$##FJ77&> 	z'2x(xyyyQ;;--ff==FFFTl$
 
 "*GJ

!??@TV\^dee
F!??@TV\]]
FBB4;;wX^C_C_``HHH$$**>*>JR\D\D\AA$++gW]B^B^__HHtw)]]^^^& {{499(FKK''//N
 N
   	r  c                     |                      |dg           }|                      |d          }|                     |d          }||d         d dd d |                     |d          d |                     |          |d
S )Nr  r   r  r  r  r  )
r  r  r  rk  r  totalr  r  rD  rI  )r  r  rW  )r  datar  r  currencyInforI  s         r  r  z hitbtc.parse_margin_modification  s    * __T<<<
z155##D,77X&$$$\6::11 
 
 	
r  c                 l    |dk    rt          | j        dz             |                     ||d|          S )a  
        remove margin from a position
        :see: https://api.hitbtc.com/#create-update-margin-account-2
        :see: 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  s       r  reduce_marginzhitbtc.reduce_margin  sL     Q;;TW  (M  M  N  N  N((6JJJr  c                 2    |                      ||d|          S )a  
        add margin
        :see: https://api.hitbtc.com/#create-update-margin-account-2
        :see: 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GGr  c                    |                                   |                     |          }d|d         i}d}|                     d|          \  }}|                     |ddg          }d}|*|                     |                     ||                    }n|d         dk    r*|                     |                     ||                    }n|d         d	k    r*|                     |                     ||                    }nM|d         dk    r*|                     |                     ||                    }nt          | j        d
z             | 	                    ||          S )ay  
        fetch the set leverage for a market
        :see: https://api.hitbtc.com/#get-futures-margin-account
        :see: 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  NrZ   rk  r5   r  r4   r6   z- fetchLeverage() not support self market type)
r  r  rn  r  r{  r  r|  r'   r  parse_leverage)r  r  r  r  r  rk  r  s          r  fetch_leveragezhitbtc.fetch_leverage4  sj    	V$$fTl
 
!??QWXX
F6L(#;<<!AA$++gW]B^B^__HHf~''EEdkkRY[aFbFbcc6))FFt{{SZ\bGcGcdd8++EEdkkRY[aFbFbcc"47-\#\]]]> ""8V444r  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||dS )Nr  r  r  )r  r  rk  longLeverageshortLeverage)r  r  rX  r,  )r  r  r  rA  leverageValues        r  r  zhitbtc.parse_leverages  sj    ##Hh77))(J??&&x88006BB)*
 
 	
r  r  c                    |t          | j        dz             |                                  |d         t          | j        dz             |                     |          }|                     |d          }|                     |d         d         dd          }|d	         d
k    rt          | j        dz             |dk     s||k    r-t          | j        dz   t          |          z   dz   |z             |d         t          |          | 	                    ||          d}| 
                    |                     ||                    S )ai  
        set the level of leverage for a market
        :see: 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
        Nz) 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  r6   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~  sp    >#DG.Y$YZZZ"#+#DG  /[  %[  \  \  \V$$!!&*:;;''x(8(DeRPP&>V##DG&SSTTTqLLh44TW'YY\_`k\l\llovvy  A  A  ATlH"66vvFF
 
 ::4;;wPV;W;WXXXr  codesc                     |                                   |                     |          }|                     ||          S )aX  
        fetch deposit and withdraw fees
        :see: 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  sA     	//774 //%@@@r  c                    |                      |dg           }|                     |          }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |d          }	|                      |d          }
|	|	dnd d}|
du r||d	<   |d d dd
|d         |<   |S )Nrf  r   r  r  defaultF)r  r   Tr~   )r~   r  )r  deposit_withdraw_feer  r  r  network_id_to_coder  )r  r  r  rf  r  r  networkEntryr  networkCodewithdrawFee	isDefaultwithdrawResults               r  parse_deposit_withdraw_feez!hitbtc.parse_deposit_withdraw_fee  s	   0 ??3
B77**3//q#h--(( 	 	A#A;L((yAAI11)<<K**<FFKi@@I"(3(?eed N D  %3z"*"& / /F:{++ r  c                     |                                   d}|                     d|d          \  }}|                     |          }|d         |d}|                     |                     ||                    }|                     ||          S )a  
        closes open positions for a market
        :see: https://api.hitbtc.com/#close-all-futures-margin-positions
        :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>`
        Nr<   r&  r  )r  r'  )r  rn  r  ,privateDeleteFuturesPositionMarginModeSymbolr  r  )r  r  ry  r  rk  r  r  r  s           r  close_positionzhitbtc.close_position  s     	
!??QWY`aa
FV$$Tl%
 
 DDT[[QXZ`EaEabb  &111r  c                     |                      | j        d          }|                     |dd          }d}t          t          |                               |||          \  }}||dk    s|du rd}||gS )a\  
         * @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
        defaultTyper5   FNTr  )r  r  r  r  r.   rn  )r  
methodNamer  defaultValuer  isMarginrk  r  s          r  rn  z$hitbtc.handle_margin_mode_and_params  s     &&t|]CC>>&(E::
"6400NNz[acopp
Fx''X-=-='
F##r  c
                 P   |                      |d          }
|                     |
d          }|w| j        dz   |z   }|                     |
dd          }|                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nerrorr   messagedescriptionr   r   )r  r  r  r  throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   )r  r  reasonurlmethodheadersbodyr  requestHeadersrequestBodyr  	errorCodefeedbackr  s                 r  handle_errorszhitbtc.handle_errors"  s    " '22$$UF33	 w}t+H((	=IIG001I9V^___001I7T\]]])))tr  r   rs  c                    |                      ||                     |                    }|                     ||          }| j        d         |         dz   |z   }	d }
t	          |                                          }t          |          }ddi}|dk    r |rd|                     |          z   }
|	|
z   }	n|                     |          }|dk    r| 	                                 t          |                                           }|d|z   g}|dk    r|
|                    |
           n|                    |           |                    |           d	                    |          }|                     |                     |          |                     | j                  t"          j        d
          }| j        dz   |z   dz   |z   }|                     |          }d|z   |d<   |	|||dS )Nr   r  zContent-Typezapplication/jsonrs  ?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  r0  hmacencodesecrethashlibsha256apiKeystring_to_base64)r  pathr   r  r  r  r  r  implodedPathr  
getRequestr  queryLengthrD  payloadpayloadString	signaturesecondPayloadencodeds                      r  signzhitbtc.sign=  s   		&$"5"5d";";<<**488is#c)L8
EJJLL!!$ii.
 U?? ' 4>>%#8#88
J&99V$$D)++---DJJLL))Iy<78G)NN:...t$$$NN9%%%GGG,,M		$++m"<"<dkk$+>V>VX_XfhmnnI K#-	9C?)KM++M::G'/''9GO$fdwOOOr  r  )e__name__
__module____qualname__r  r  r   r   r  r   r  r  r  r  r!  r   r)  r1  r   r6  r   r   rB  r4  r   r   ri  r   rs  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  floatr  objectr  r3  r  r   rC  r
   rE  r   r}   rN  rY  r~   rh  rt  ry  r}  rx  r  r  r  rc  r   r  r  r  r  r	   r  r  r  r  r  r  rn  r  r  __classcell__)r  s   @r  r.   r.      s       x	 x	 x	 x	 x	t# # # $& G G$v, G G G GR ') g gZ g g g gR% % % 8: 
 
3 
 
 
 
B 79 $
 $
# $
 $
 $
 $
L
) 
) 
) 
) 
) $& ", ",( ", ", ", ",H 02 3 33 3f 3 3 3 3: 04B 'G 'GW 'G7 'G 'G 'G 'GR) )6 )V ) ) ) )V 6:UW " "3 "s "# "\`af\g " " " "H -1tRV_a )A )Ac )A )AC )A )A )A )AVc c c5 c c c cJ&Q &Q &QP: : :3 3 3R
 R
x R
; R
 R
 R
 R
h 6:[_hj 
^ 
^s 
^# 
^UX 
^ost  pA 
^ 
^ 
^ 
^ *.Dt\^ 
U 
U3 
Uc 
U 
Ucghsct 
U 
U 
U 
U -1tRV_a 
V 
Vc 
V 
VC 
Vfjkvfw 
V 
V 
V 
V 48dSU       6 :>b P Ps P3 PY P P P P(
 
V 
?R 
 
 
 
* 57 8 8 8;N 8 8 8 8: )+  {    B 26DW[df EL EL# ELc ELQT ELkoptku EL EL EL ELN
 
 
4 
 
 
 
B 154VZce *U *U# *US *UPS *Ujnotju *U *U *U *UX 26b 8/ 8/c 8/3 8/ 8/ 8/ 8/t 9=4^bkm MA MAS MA# MAS MAX[ MA MA MA MA^ /3TXac 8A 8A 8A3 8Ac 8Ahlmrhs 8A 8A 8A 8At 7;2 %2 %23 %2 %2 %2 %2 %2N /32 #3 #3 #3 #3 #3 #3J 37r %2 %2s %2C %2 %2 %2 %2N `drv  @B 2 2S 2# 2Y 2i 2Y\ 2lo 2 2 2 2@ gksu "2 "23 "2i "2y "2RW "2`c "2 "2 "2 "2H CG  [_  hj 6! 6!6 6!s 6!) 6![d 6!ns 6!| 6!  UX 6! 6! 6! 6!p	: 	: 	:u u u5 u u u un 7;2 :B :B$s) :B+ :B :B :B :Bx
 
J 
 
 
 
 [] "7 "7S "7% "7c "7c "7an "7 "7 "7 "7H
 
 
 
 
 
(
S 
 
 
 
2 ?C2 ': ':S ':% ': ': ': ':R 6:" /E /E7 /E /E /E /Eb 8<$]ajl GO GO GOC GOWZ GO GO GO GOR 26b A Aw A A A AF 24 ?5 ?5S ?5 ?5 ?5 ?5BR Rv R R R Rh F    6 79 : :# : : : :B 68 9 9 9 9 9 9B$
 $
6 $
 $
 $
 $
L FH 3 33 3L^ 3 3 3 3j#
 #
f #
HZ #
 #
 #
 #
J 9; K KC K?Q K K K K  68 H H H<N H H H H 24 =5 =5S =5 =5 =5 =5 =5~	
 	
x 	
 	
 	
 	
 9=R Y YS Y# Y Y Y Y: <@ #A #A #A #A #A #AJ- - - - - -^ =A !2 !2S !2	 !2PU !2 !2 !2 !2F @BPT $ $ $ $ $ $   6 &eBSW P P P P P P P Pr  r.   )3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   typingr   ccxt.base.errorsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   ccxt.base.decimal_to_precisionr+   ccxt.base.preciser,   r.    r  r  <module>r      s   ( ' ' ' ' ' , , , , , ,  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 * * * * * * 4 4 4 4 4 4 % % % % % %4P 4P 4P 4P 4PX{ 4P 4P 4P 4P 4Pr  