
    ei                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"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(m0Z0 d dl(m1Z1 d dl(m2Z2 d dl(m3Z3 d dl(m4Z4 d dl(m5Z5 d dl(m6Z6 d dl(m7Z7 d dl(m8Z8 d dl9m:Z: d dl9m;Z; d dl<m=Z=  G d dee          Z>dS )    )Exchange)ImplicitAPIN) AccountAnyADLBalancesBorrowInterest
CurrenciesCurrencyDepositAddressIntIsolatedBorrowRateIsolatedBorrowRatesLedgerEntryLeverageTierLeverageTiersMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountNotEnabled)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)OperationFailed)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)RequestTimeout)TRUNCATE)	TICK_SIZE)Precisec                   
    e Zd Zdef fdZi fdZi fdefdZddede	de
fdZi fd	ede
fd
Zdi fdefdZi fdefdZdi fd	efdZd Zi fdee	         fdZi fdedefdZdefdZddede	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i fdefdZdde	fdZdi fd	ededefdZ ddede	de!fd Z"dddi fded	ed!edefd"Z#dddi fded	ed!edefd#Z$dddi fd	ed!edefd$Z%dd%i fd	ed!ededee!         fd&Z&dde	de'fd'Z(d(ddi fd	ed)ed!ededee'         f
d*Z)i fdee*         fd+Z+d, Z,ddi fded-ed	efd.Z-i fde.fd/Z/dd0ed1ef fd2Z0dd3ed1ef fd4Z1i fde2fd5Z3di fded	efd6Z4d7 Z5dddi fd	ed!edefd8Z6dddi fd	ed!edefd9Z7dddi fd	ed!edefd:Z8dddi fd	ed!edefd;Z9dddi fd	ed!edefd<Z:dddi fd	ed!ededee;         fd=Z<dddi fd	ed!ededee;         fd>Z=dddi fd	ed!ededee;         fd?Z>d@efdAZ?ddBede	de;fdCZ@i fd	edDeAfdEZBdddi fd	edeCdFeDdGeAdHeEdIeEdJeEde;fdKZFdi fd	edeCdFeDdGeAdHeEf
dLZGdi fd	edeCdFeDdGeAdHeEf
dMZHdi fd	edeCdFeDdGeAdHeEf
dNZIi fdOeeJ         fdPZKdi fded	efdQZLdi fdRee         d	efdSZMdT ZNdi fd	efdUZOi fdVefdWZPddXeQfdYZRi fdZedeeS         fd[ZTi fdZedeSfd\ZUddi fdZefd]ZVdddi fdZed!ededeeW         fd^ZXdddi fdZed!ededeeW         fd_ZYdd`edXeQdeWfdaZZd@efdbZ[di fdZedGeAdceddedeWf
deZ\ddfedXeQde]fdgZ^i fdZedGeAdhediede]f
djZ_i fde`fdkZaddlede	debfdmZcdddi fd	ed!edefdnZddde	deefdoZfdp Zgi fd	edeefdqZhdi fdedeifdrZjddddi fdZed	ed!ededeek         f
dsZlddlede	dekfdtZmdu Zndvdwi ddfdxZodyepdzed{ed|ed}ed~efdZqdddi fd	ed!edefdZrdi fdepd	efdZsdde	fdZtddede	fdZudi fdedeev         fdZwi fd	efdZxd ZyddedXeQdezfdZ{dddi fdZed!ededeez         fdZ|di fdede}fdZ~dde	dee         fdZdddi fd	ed!edefdZdi fdefdZi fd	efdZdde	fdZi fd	edZedGeAfdZi fdZedGeAfdZi fd	edZefdZi fdZefdZddXeQfdZdddi fd	ed!edefdZdi fdefdZddXeQfdZd Zd Zddi fd	ed!edefdZdde	fdZdi fd	edFeDde;fdZdi fded	efdZdi fdedee         fdZddlede	defdZ xZS )htxreturnc                 "   |                      t          t          |                                           i ddddddgddd	| j        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d.dd/dd0dd1dd2dd3d d4dd5d i d6d d7d d8d d9dd:d!d;d!d<dd=d d>dd?d d@ddAddBdCdDddEddFddGdi dHddIddJd!dKddLd dMddNddOd dPd!dQddRddSd!dTdCdUddVddWd!dXdi dYddZdd[dd\dd]d d^dd_dd`ddad dbddcdddddeddfdCdgddhddid!i djd!dkddlddmd!dnddoddpddqddrddsd!dtddud dvd dwd dxd dyddzd dd d dddd!dd ddd{d|d}d~ddddddddd
dddddddddddddddddddddddddg ddddddddii ddddddddddddddddddddddddddddddddddddddddddddddi dddddddddddddddddddddddddddddddddddddddddŜdƜdddddddǜii dddddddd̓ddddddddѓddѓddѓddѓddѓddddddddddddddddddۜi ddddddѓddddddѓddddѓddddddÓddÓddÓddÓdddddddddddƜddddiidddiidddiiddddiidddiiddidi ddddddddddddddddddddddddddddddddddddddddd ii dddddddddd̓ddddddd	dd
dddddddd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dddddddddddd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d0dd1dÓd2dÓd3di d4dѓd5dd6dd7dd8dѓd9dѓd:dd;dd<dd=dd>dÓd?dÓd@dÓdAdÓdBddCddDdddddddĐdEdƜdFdi dGddHddIddJddKddLddMddNddOddPddddQddddRddSddTddUdi dVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfdi dgddhddiddjddkddlddmddnddoddpddqddrddsddtdduddvddwdi dxddyddzdd{dd|dd}dd~dddddddddddddddddddddi dddddddddddddddddddddddddddddddddddddddddddddddddii dddddddddddddddddddddddddddddddddddddddddddd	i ddddddddddddddddddddddddddddddddddi dddddddddddddddddddǐdȓddddddddddddddi ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddi dddddddddddddddddddddddddddd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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d0dd1dd2dd3dd4dd5di d6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDddEddFdi dGdȓdHdȓdIddJddKddLddMddNddOddPddQddRddSddTddUddVddWdi dXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfddgddhdi diddjddkddlddmddnddoddpddqddrddsddtdduddvddwddxddydi dzdd{dd|dd}dd~ddddddddddddddddddddddddddddddddddƜdFddddd!d|                     d          |                     d          didt          t          t          d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          t          t          t          t          t          t          t          t"          dŜdƜdt$          di dd!dUddddd˜id̐d͓dd!dYddidАdd!idddӐdԓdՐd֓dאd֐dؐdِdڜdi 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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+d,d,d-d-d.d.d/d/d0d0d1d1d2d2d3d3i d4d4d5d5d6d6d7d7d8d8d9d9d:d:d;d;d<d<d=d=d>d>d?d?d@d@dAdAdBdBdCdCdDdDi dEdEdFdFdGdGdHdHdIdIdJdJdKdKdLdLdMdMdNdNdOdOdPdPdQdQdRdRdSdSdTdTdUdUi dVdVdWdWdXdXdYdYdZdZd[d[d\d\d]d^d_d_d`dadbdcdddddededfdfdgdgdhdhdidii djdjdkdkdldldmdmdndndodpdqdqdrdrdsdsdtdtdududvdvdwdwdxdxdydydzdz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dddddddddddiddddddddddddddddd
ddddddddddi dddddddddddddddddddddddddddddddddddd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Ɯddid!dȐdɐdd!d˜d!d!d!d!d̜d!dd!dd!d͜d!dd!dȐdʐdd!dϜd!dd!dʐdȐdΐdd!dќddidӜ	ddddddԜdǐdiddidd!d!dĐdלdd!d!dĐdؐdٜdd!d!ddĐdؐdАdڜddidܜdݐdidݐdidߜdݐdidݐdidߜddd          S (  Nidr:   nameHTX	countriesCN	rateLimitd   	userAgent	chrome100	certifiedTversionv1hostnamezapi.huobi.proprohasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscloseAllPositionsFclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingPercentOrdercreateTriggerOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLastPricesfetchLedgerfetchLedgerEntryfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginAdjustmentHistoryfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionADLRankfetchPositionHistoryfetchPositionsfetchPositionsADLRankfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawAddressesfetchWithdrawal)fetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModesetPositionModesignIntransferwithdraw
timeframes1min5min15min30min60min4hour1day1week1mon1year)
1m5m15m30m1h4h1d1w1M1yurlszchttps://user-images.githubusercontent.com/1294454/76137448-22748a80-604e-11ea-8069-6e389271911d.jpgzapi.hbdm.vnzstatus.huobigroup.comzstatus-dm.huobigroup.comz!status-linear-swap.huobigroup.com)inverselinearzstatus-swap.huobigroup.com)rM   rP   rO   )contractrM   statuszhttps://{hostname})r   r   rM   publicprivatev2Public	v2Privatezhttps://www.huobi.comz;https://www.htx.com.vc/invite/en-us/1h?invite_code=6rmm2223g333333?)urldiscount)z+https://huobiapi.github.io/docs/spot/v1/en/z)https://huobiapi.github.io/docs/dm/v1/en/z9https://huobiapi.github.io/docs/coin_margined_swap/v1/en/z0https://huobiapi.github.io/docs/usdt_swap/v1/en/z.https://www.huobi.com/en-us/opend/newApiPages/z https://www.huobi.com/about/fee/)logo	hostnamesapiwwwreferraldocfeesr   get   )zreference/currencieszmarket-statuszaccount/ledgerzaccount/withdraw/quotazaccount/withdraw/addresszaccount/deposit/addresszaccount/repayment   zreference/transact-fee-ratezaccount/asset-valuationg?zpoint/accountzsub-user/user-listzsub-user/user-statezsub-user/account-listzsub-user/deposit-addresszsub-user/query-depositzuser/api-keyzuser/uidzalgo-orders/openingzalgo-orders/history)zalgo-orders/specificz
c2c/offers	c2c/offerzc2c/transactionsc2c/repaymentzc2c/accountzetp/referencezetp/transactionszetp/transactionzetp/rebalancez	etp/limitzaccount/transferzpoint/transferzsub-user/managementzsub-user/creationzsub-user/tradable-marketzsub-user/transferabilityzsub-user/api-key-generationzsub-user/api-key-modificationzsub-user/api-key-deletionzsub-user/deduct-modezalgo-orderszalgo-orders/cancel-all-afterzalgo-orders/cancellationr   zc2c/cancellationzc2c/cancel-all
   2   )r   zc2c/transferzetp/creationzetp/redemptionzetp/{transactId}/cancelzetp/batch-cancel)r   post)zcommon/symbolszcommon/currencyszcommon/timestampzcommon/exchangezsettings/currencyszaccount/accountszaccount/accounts/{id}/balancezaccount/accounts/{sub-uid}zaccount/history   zcross-margin/loan-infozmargin/loan-infozfee/fee-rate/getzorder/openOrdersg?zorder/orderszorder/orders/{id}zorder/orders/{id}/matchresultszorder/orders/getClientOrderzorder/historyzorder/matchresultszquery/deposit-withdrawzmargin/loan-orderszmargin/accounts/balance)zcross-margin/loan-orderszcross-margin/accounts/balancezpoints/actionszpoints/orderszsubuser/aggregate-balancezstable-coin/exchange_ratezstable-coin/quotezfutures/transferzorder/batch-orderszorder/orders/placez$order/orders/submitCancelClientOrderz"order/orders/batchCancelOpenOrderszorder/orders/{id}/submitcancelzorder/orders/batchcancelzdw/withdraw/api/createzdw/withdraw-virtual/{id}/cancelzdw/transfer-in/marginzdw/transfer-out/marginzmargin/orderszmargin/orders/{id}/repayzcross-margin/transfer-inzcross-margin/transfer-outzcross-margin/orders)zcross-margin/orders/{id}/repayzstable-coin/exchangezsubuser/transferr   zapi/v2/summary.jsonzv2/market-statuszv1/common/symbolszv1/common/currencyszv2/settings/common/currencieszv2/reference/currencieszv1/common/timestampzv1/common/exchangezv1/settings/common/chainszv1/settings/common/currencyszv1/settings/common/symbolszv2/settings/common/symbolsz!v1/settings/common/market-symbolszmarket/history/candleszmarket/history/klinezmarket/detail/mergedzmarket/tickerszmarket/detail)market/depthmarket/trademarket/history/tradez
market/etpzv2/etp/referencezv2/etp/rebalancezv1/account/accountsz(v1/account/accounts/{account-id}/balancezv2/account/valuationzv2/account/asset-valuationzv1/account/historyzv2/account/ledgerzv2/point/accountzv2/account/deposit/addresszv2/account/withdraw/quotazv2/account/withdraw/addresszv1/query/deposit-withdrawz!v1/query/withdraw/client-order-idzv2/user/api-keyzv2/user/uidzv2/sub-user/user-listzv2/sub-user/user-statezv2/sub-user/account-listzv2/sub-user/deposit-addresszv2/sub-user/query-depositzv1/subuser/aggregate-balancezv1/account/accounts/{sub-uid}zv1/order/openOrderszv1/order/orders/{order-id}zv1/order/orders/getClientOrderz&v1/order/orders/{order-id}/matchresultz'v1/order/orders/{order-id}/matchresultszv1/order/orderszv1/order/historyzv1/order/matchresultszv2/reference/transact-fee-ratezv2/algo-orders/openingzv2/algo-orders/historyzv2/algo-orders/specific)zv1/margin/loan-infozv1/margin/loan-orderszv1/margin/accounts/balancezv1/cross-margin/loan-infozv1/cross-margin/loan-ordersz v1/cross-margin/accounts/balancev2/account/repaymentzv1/stable-coin/quotezv1/stable_coin/exchange_ratezv2/etp/transactionszv2/etp/transactionzv2/etp/limitzv1/account/transferzv1/futures/transferzv2/point/transferzv2/account/transferzv1/dw/withdraw/api/createz+v1/dw/withdraw-virtual/{withdraw-id}/cancelzv2/sub-user/deduct-modezv2/sub-user/creationzv2/sub-user/managementzv2/sub-user/tradable-marketzv2/sub-user/transferabilityzv2/sub-user/api-key-generationz v2/sub-user/api-key-modificationzv2/sub-user/api-key-deletionzv1/subuser/transferzv1/trust/user/active/creditzv1/order/orders/placezv1/order/batch-orderszv1/order/auto/placez'v1/order/orders/{order-id}/submitcancelz'v1/order/orders/submitCancelClientOrderz%v1/order/orders/batchCancelOpenOrderszv1/order/orders/batchcancelzv2/algo-orders/cancel-all-afterzv2/algo-orderszv2/algo-orders/cancellationr   zv1/dw/transfer-in/marginzv1/dw/transfer-out/marginzv1/margin/ordersz!v1/margin/orders/{order-id}/repayzv1/cross-margin/transfer-inzv1/cross-margin/transfer-outzv1/cross-margin/orders)z'v1/cross-margin/orders/{order-id}/repayzv1/stable-coin/exchangezv2/etp/creationzv2/etp/redemptionzv2/etp/{transactId}/cancelzv2/etp/batch-cancel)r   r   zapi/v1/timestampz
heartbeat/zapi/v1/contract_contract_infozapi/v1/contract_indexzapi/v1/contract_query_elementszapi/v1/contract_price_limitzapi/v1/contract_open_interestzapi/v1/contract_delivery_pricer   z
market/bboz%index/market/history/mark_price_klinezmarket/detail/batch_mergedzv2/market/detail/batch_mergedr   r   zapi/v1/contract_risk_infozapi/v1/contract_insurance_fundzapi/v1/contract_adjustfactorz!api/v1/contract_his_open_interestzapi/v1/contract_ladder_marginzapi/v1/contract_api_statez#api/v1/contract_elite_account_ratioz$api/v1/contract_elite_position_ratioz"api/v1/contract_liquidation_ordersz"api/v1/contract_settlement_recordszindex/market/history/indexzindex/market/history/basisz*api/v1/contract_estimated_settlement_pricez"api/v3/contract_liquidation_orderszswap-api/v1/swap_contract_infozswap-api/v1/swap_indexzswap-api/v1/swap_query_elementszswap-api/v1/swap_price_limitzswap-api/v1/swap_open_interestzswap-ex/market/depthzswap-ex/market/bbozswap-ex/market/history/klinez*index/market/history/swap_mark_price_klinezswap-ex/market/detail/mergedz%v2/swap-ex/market/detail/batch_mergedz-index/market/history/swap_premium_index_klinez"swap-ex/market/detail/batch_mergedzswap-ex/market/tradezswap-ex/market/history/tradezswap-api/v1/swap_risk_infozswap-api/v1/swap_insurance_fundzswap-api/v1/swap_adjustfactorz"swap-api/v1/swap_his_open_interestzswap-api/v1/swap_ladder_marginzswap-api/v1/swap_api_statez$swap-api/v1/swap_elite_account_ratioz%swap-api/v1/swap_elite_position_ratioz+swap-api/v1/swap_estimated_settlement_pricez#swap-api/v1/swap_liquidation_ordersz#swap-api/v1/swap_settlement_recordszswap-api/v1/swap_funding_ratez#swap-api/v1/swap_batch_funding_ratez(swap-api/v1/swap_historical_funding_ratez#swap-api/v3/swap_liquidation_ordersz.index/market/history/swap_estimated_rate_klinezindex/market/history/swap_basisz%linear-swap-api/v1/swap_contract_infozlinear-swap-api/v1/swap_indexz&linear-swap-api/v1/swap_query_elementsz#linear-swap-api/v1/swap_price_limitz%linear-swap-api/v1/swap_open_interestzlinear-swap-ex/market/depthzlinear-swap-ex/market/bboz#linear-swap-ex/market/history/klinez1index/market/history/linear_swap_mark_price_klinez#linear-swap-ex/market/detail/mergedz)linear-swap-ex/market/detail/batch_mergedz,v2/linear-swap-ex/market/detail/batch_mergedzlinear-swap-ex/market/tradez#linear-swap-ex/market/history/tradez!linear-swap-api/v1/swap_risk_infoz2swap-api/v1/linear-swap-api/v1/swap_insurance_fundz$linear-swap-api/v1/swap_adjustfactorz*linear-swap-api/v1/swap_cross_adjustfactorz)linear-swap-api/v1/swap_his_open_interestz%linear-swap-api/v1/swap_ladder_marginz+linear-swap-api/v1/swap_cross_ladder_marginz!linear-swap-api/v1/swap_api_state)z,linear-swap-api/v1/swap_cross_transfer_statez)linear-swap-api/v1/swap_cross_trade_statez+linear-swap-api/v1/swap_elite_account_ratioz,linear-swap-api/v1/swap_elite_position_ratioz*linear-swap-api/v1/swap_liquidation_ordersz*linear-swap-api/v1/swap_settlement_recordsz$linear-swap-api/v1/swap_funding_ratez*linear-swap-api/v1/swap_batch_funding_ratez/linear-swap-api/v1/swap_historical_funding_ratez*linear-swap-api/v3/swap_liquidation_ordersz4index/market/history/linear_swap_premium_index_klinez5index/market/history/linear_swap_estimated_rate_klinez&index/market/history/linear_swap_basisz2linear-swap-api/v1/swap_estimated_settlement_pricezapi/v1/contract_sub_auth_listz"api/v1/contract_api_trading_statuszswap-api/v1/swap_sub_auth_listz#swap-api/v1/swap_api_trading_statusz%linear-swap-api/v1/swap_sub_auth_listz*linear-swap-api/v1/swap_api_trading_statusz+linear-swap-api/v1/swap_cross_position_sidez%linear-swap-api/v1/swap_position_sidez'linear-swap-api/v3/unified_account_infoz4linear-swap-api/v3/fix_position_margin_change_recordz,linear-swap-api/v3/swap_unified_account_typez4linear-swap-api/v3/linear_swap_overview_account_infozv5/account/balancezv5/account/asset_modezv5/trade/position/openszv5/trade/order/openszv5/trade/order/details)	zv5/trade/order/historyv5/trade/orderv5/position/leverv5/position/modezv5/position/risk/limitzv5/position/risk/limit_tierzv5/market/risk/limitz#v5/market/assets_deduction_currencyzv5/market/multi_assets_marginz!api/v1/contract_balance_valuationzapi/v1/contract_account_infozapi/v1/contract_position_infozapi/v1/contract_sub_authz api/v1/contract_sub_account_listz%api/v1/contract_sub_account_info_listz api/v1/contract_sub_account_infoz!api/v1/contract_sub_position_infoz api/v1/contract_financial_recordz&api/v1/contract_financial_record_exactz'api/v1/contract_user_settlement_recordszapi/v1/contract_order_limitzapi/v1/contract_feezapi/v1/contract_transfer_limitzapi/v1/contract_position_limitz%api/v1/contract_account_position_infoz#api/v1/contract_master_sub_transferz*api/v1/contract_master_sub_transfer_recordz$api/v1/contract_available_level_ratez api/v3/contract_financial_recordz&api/v3/contract_financial_record_exactzapi/v1/contract-cancel-afterzapi/v1/contract_orderzapi/v1/contract_batchorderzapi/v1/contract_cancelzapi/v1/contract_cancelallz!api/v1/contract_switch_lever_rate   zapi/v1/lightning_close_positionzapi/v1/contract_order_infozapi/v1/contract_order_detailzapi/v1/contract_openorderszapi/v1/contract_hisorderszapi/v1/contract_hisorders_exactzapi/v1/contract_matchresultsz"api/v1/contract_matchresults_exactzapi/v3/contract_hisorderszapi/v3/contract_hisorders_exactzapi/v3/contract_matchresultsz"api/v3/contract_matchresults_exactzapi/v1/contract_trigger_orderzapi/v1/contract_trigger_cancelz!api/v1/contract_trigger_cancelallz"api/v1/contract_trigger_openordersz!api/v1/contract_trigger_hisorderszapi/v1/contract_tpsl_orderzapi/v1/contract_tpsl_cancelzapi/v1/contract_tpsl_cancelallzapi/v1/contract_tpsl_openorderszapi/v1/contract_tpsl_hisordersz#api/v1/contract_relation_tpsl_orderzapi/v1/contract_track_orderzapi/v1/contract_track_cancelzapi/v1/contract_track_cancelallz api/v1/contract_track_openorderszapi/v1/contract_track_hisordersz"swap-api/v1/swap_balance_valuationzswap-api/v1/swap_account_infozswap-api/v1/swap_position_infoz&swap-api/v1/swap_account_position_infozswap-api/v1/swap_sub_authz!swap-api/v1/swap_sub_account_listz&swap-api/v1/swap_sub_account_info_listz!swap-api/v1/swap_sub_account_infoz"swap-api/v1/swap_sub_position_infoz!swap-api/v1/swap_financial_recordz'swap-api/v1/swap_financial_record_exactz(swap-api/v1/swap_user_settlement_recordsz%swap-api/v1/swap_available_level_ratezswap-api/v1/swap_order_limitzswap-api/v1/swap_feezswap-api/v1/swap_transfer_limitzswap-api/v1/swap_position_limitz$swap-api/v1/swap_master_sub_transferz+swap-api/v1/swap_master_sub_transfer_recordz!swap-api/v3/swap_financial_recordz'swap-api/v3/swap_financial_record_exactzswap-api/v1/swap-cancel-afterzswap-api/v1/swap_orderzswap-api/v1/swap_batchorderzswap-api/v1/swap_cancelzswap-api/v1/swap_cancelallz)swap-api/v1/swap_lightning_close_positionz"swap-api/v1/swap_switch_lever_ratezswap-api/v1/swap_order_infozswap-api/v1/swap_order_detailzswap-api/v1/swap_openorderszswap-api/v1/swap_hisordersz swap-api/v1/swap_hisorders_exactzswap-api/v1/swap_matchresultsz#swap-api/v1/swap_matchresults_exactzswap-api/v3/swap_matchresultsz#swap-api/v3/swap_matchresults_exactzswap-api/v3/swap_hisordersz swap-api/v3/swap_hisorders_exactzswap-api/v1/swap_trigger_orderzswap-api/v1/swap_trigger_cancelz"swap-api/v1/swap_trigger_cancelallz#swap-api/v1/swap_trigger_openordersz"swap-api/v1/swap_trigger_hisorderszswap-api/v1/swap_tpsl_orderzswap-api/v1/swap_tpsl_cancelzswap-api/v1/swap_tpsl_cancelallz swap-api/v1/swap_tpsl_openorderszswap-api/v1/swap_tpsl_hisordersz$swap-api/v1/swap_relation_tpsl_orderzswap-api/v1/swap_track_orderzswap-api/v1/swap_track_cancelz swap-api/v1/swap_track_cancelallz!swap-api/v1/swap_track_openordersz swap-api/v1/swap_track_hisordersz,linear-swap-api/v1/swap_lever_position_limitz2linear-swap-api/v1/swap_cross_lever_position_limitz)linear-swap-api/v1/swap_balance_valuationz$linear-swap-api/v1/swap_account_infoz*linear-swap-api/v1/swap_cross_account_infoz%linear-swap-api/v1/swap_position_infoz+linear-swap-api/v1/swap_cross_position_infoz-linear-swap-api/v1/swap_account_position_infoz3linear-swap-api/v1/swap_cross_account_position_infoz linear-swap-api/v1/swap_sub_authz(linear-swap-api/v1/swap_sub_account_listz.linear-swap-api/v1/swap_cross_sub_account_listz-linear-swap-api/v1/swap_sub_account_info_listz3linear-swap-api/v1/swap_cross_sub_account_info_listz(linear-swap-api/v1/swap_sub_account_infoz.linear-swap-api/v1/swap_cross_sub_account_infoz)linear-swap-api/v1/swap_sub_position_infoz/linear-swap-api/v1/swap_cross_sub_position_infoz(linear-swap-api/v1/swap_financial_recordz.linear-swap-api/v1/swap_financial_record_exactz/linear-swap-api/v1/swap_user_settlement_recordsz5linear-swap-api/v1/swap_cross_user_settlement_recordsz,linear-swap-api/v1/swap_available_level_ratez2linear-swap-api/v1/swap_cross_available_level_ratez#linear-swap-api/v1/swap_order_limitzlinear-swap-api/v1/swap_feez&linear-swap-api/v1/swap_transfer_limitz,linear-swap-api/v1/swap_cross_transfer_limitz&linear-swap-api/v1/swap_position_limitz,linear-swap-api/v1/swap_cross_position_limitz+linear-swap-api/v1/swap_master_sub_transferz2linear-swap-api/v1/swap_master_sub_transfer_recordz&linear-swap-api/v1/swap_transfer_innerz(linear-swap-api/v3/swap_financial_recordz.linear-swap-api/v3/swap_financial_record_exactzlinear-swap-api/v1/swap_orderz#linear-swap-api/v1/swap_cross_orderz"linear-swap-api/v1/swap_batchorderz(linear-swap-api/v1/swap_cross_batchorderzlinear-swap-api/v1/swap_cancelz$linear-swap-api/v1/swap_cross_cancelz!linear-swap-api/v1/swap_cancelallz'linear-swap-api/v1/swap_cross_cancelallz)linear-swap-api/v1/swap_switch_lever_ratez/linear-swap-api/v1/swap_cross_switch_lever_ratez0linear-swap-api/v1/swap_lightning_close_positionz6linear-swap-api/v1/swap_cross_lightning_close_positionz"linear-swap-api/v1/swap_order_infoz(linear-swap-api/v1/swap_cross_order_infoz$linear-swap-api/v1/swap_order_detailz*linear-swap-api/v1/swap_cross_order_detailz"linear-swap-api/v1/swap_openordersz(linear-swap-api/v1/swap_cross_openordersz!linear-swap-api/v1/swap_hisordersz'linear-swap-api/v1/swap_cross_hisordersz'linear-swap-api/v1/swap_hisorders_exactz-linear-swap-api/v1/swap_cross_hisorders_exactz$linear-swap-api/v1/swap_matchresultsz*linear-swap-api/v1/swap_cross_matchresultsz*linear-swap-api/v1/swap_matchresults_exactz0linear-swap-api/v1/swap_cross_matchresults_exactz&linear-swap-api/v1/linear-cancel-afterz,linear-swap-api/v1/swap_switch_position_modez2linear-swap-api/v1/swap_cross_switch_position_modez$linear-swap-api/v3/swap_matchresultsz*linear-swap-api/v3/swap_cross_matchresultsz*linear-swap-api/v3/swap_matchresults_exactz0linear-swap-api/v3/swap_cross_matchresults_exactz!linear-swap-api/v3/swap_hisordersz'linear-swap-api/v3/swap_cross_hisordersz'linear-swap-api/v3/swap_hisorders_exactz-linear-swap-api/v3/swap_cross_hisorders_exactz-linear-swap-api/v3/fix_position_margin_changez+linear-swap-api/v3/swap_switch_account_typez)linear-swap-api/v3/linear_swap_fee_switchz%linear-swap-api/v1/swap_trigger_orderz+linear-swap-api/v1/swap_cross_trigger_orderz&linear-swap-api/v1/swap_trigger_cancelz,linear-swap-api/v1/swap_cross_trigger_cancelz)linear-swap-api/v1/swap_trigger_cancelallz/linear-swap-api/v1/swap_cross_trigger_cancelallz*linear-swap-api/v1/swap_trigger_openordersz0linear-swap-api/v1/swap_cross_trigger_openordersz)linear-swap-api/v1/swap_trigger_hisordersz/linear-swap-api/v1/swap_cross_trigger_hisordersz"linear-swap-api/v1/swap_tpsl_orderz(linear-swap-api/v1/swap_cross_tpsl_orderz#linear-swap-api/v1/swap_tpsl_cancelz)linear-swap-api/v1/swap_cross_tpsl_cancelz&linear-swap-api/v1/swap_tpsl_cancelallz,linear-swap-api/v1/swap_cross_tpsl_cancelallz'linear-swap-api/v1/swap_tpsl_openordersz-linear-swap-api/v1/swap_cross_tpsl_openordersz&linear-swap-api/v1/swap_tpsl_hisordersz,linear-swap-api/v1/swap_cross_tpsl_hisordersz+linear-swap-api/v1/swap_relation_tpsl_orderz1linear-swap-api/v1/swap_cross_relation_tpsl_orderz#linear-swap-api/v1/swap_track_orderz)linear-swap-api/v1/swap_cross_track_orderz$linear-swap-api/v1/swap_track_cancelz*linear-swap-api/v1/swap_cross_track_cancelz'linear-swap-api/v1/swap_track_cancelallz-linear-swap-api/v1/swap_cross_track_cancelallz(linear-swap-api/v1/swap_track_openordersz.linear-swap-api/v1/swap_cross_track_openordersz'linear-swap-api/v1/swap_track_hisordersz-linear-swap-api/v1/swap_cross_track_hisordersr   zv5/trade/batch_orderszv5/trade/cancel_order)zv5/trade/cancel_batch_orderszv5/trade/cancel_all_orderszv5/trade/positionzv5/trade/position_allr   r   z!v5/account/fee_deduction_currency)r   r   r   r   r   rM   r   r   trading0.002)feeSide	tierBased
percentagemakertaker
exceptions)zTcontract is restricted of closing positions on API.  Please contact customer servicemaintainzAPI key has no permission4031010100310131017103410361039104110471048106110511066106710941220130314614007zbad-requestzvalidation-format-errorzvalidation-constraints-requiredzbase-date-limit-errorzapi-not-support-temp-addrtimeoutzgateway-internal-errorz)account-frozen-balance-insufficient-errorzinvalid-amountz!order-limitorder-amount-min-errorz!order-limitorder-amount-max-errorz"order-marketorder-amount-min-errorz order-limitorder-price-min-errorz order-limitorder-price-max-errorz$order-limitorder-price-buy-min-errorz$order-limitorder-price-buy-max-errorz%order-limitorder-price-sell-min-errorz%order-limitorder-price-sell-max-errorzorder-stop-order-hit-triggerzorder-value-min-errorzorder-invalid-pricezorder-holding-limit-failedz order-orderprice-precision-errorzorder-etp-nav-price-max-errorzorder-orderstate-errorzorder-queryorder-invalidzorder-update-errorzapi-signature-check-failedzapi-signature-not-validzbase-record-invalidzbase-symbol-trade-disabled)zbase-symbol-errorzsystem-maintenancez#base-request-exceed-frequency-limitzrate-too-many-requestszinvalid symbolzsymbol trade not open nowzrequire-symbolzinvalid-addresszbase-currency-chain-errorzdw-insufficient-balancezbase-withdraw-fee-errorzdw-withdraw-min-limitzrequest limit)broadexactprecisionModeoptionsinclude_OS_certificatestypes)rM   r   r   timeDifferencer   adjustForTimeDifferenceuseHistoricalEndpointForSpotr   
includeFeedefaultTypedefaultSubTyper   defaultNetworkERC20defaultNetworksBTCTRC20)ETHr#  USDTnetworksTRXr%  SOLSOLANAHRC20HECOBEP20BSCXMRLTCXRPXLMCRONOSCROGLMRPOLYGONMATICBTTCUBEIOSTNEOKLAYEOSTHETANASNULSQTUMFTMCELODOGE	DOGECHAINNEARSTEPBITCICARDANOADAETCLUKMINEPLEXDASHZECIOTANEON3XEMHCLSKDCRBTGSTEEMBTSICXWAVESCMTBTMVETXZCACTSMTBCDWAXWAX1WICCELFZILELABCXSBTCBIFICTXCWANPOLYXPAIWTCDGBXVGAACAESEELEBCVGRSARDRNANOZENRBTCBSVGASXTZLAMBCVNT1DOCKSCKMDETNTOPIRISUGASTTNEWTONVSYSFSNBHDONEEMCKBEOSSHIVERVNDOTKSMBANDOEP4NBSFISARHBARFILMASSKAVAXYMENJCRUSTICPCSPRFLOWIOTXLATAPTXCHMINAXECECASHXPRTCCAACAAOTICOTIAKTARSASTRAZEROBLDBRISECOREDESODFIEGLDERGETHFETHFAIRETHWEVMOSFIOFLRFINSCHIAKMAKYVEMEVMOVRNODLOASOSMOPAYCOINPOKTPYGREISCRTSDNSEISGBSUISXPSOLARSYSTENETTONUNQUYUWEMIXXDCXPLA)r  r  fetchOrdersByStatesMethod spot_private_get_v1_order_orders!createMarketBuyOrderRequiresPricelanguagezen-USbroker
AA03022abcaccountsByTypefutures)rM   fundingrP   accountsByIdotcpointsuper-margin
investmentborrowgrid-tradingdeposit-earningotc-options)
rM   rN   r  r  r  r  r  r  r  r  )rJ   r  )
stop-limitbuy-stop-limitsell-stop-limitstop-limit-fokbuy-stop-limit-foksell-stop-limit-foklimitz	buy-limitz
sell-limitioczbuy-ioczsell-ioclimit-makerzbuy-limit-makerzsell-limit-makerr  r  r  	limit-fokzbuy-limit-fokzsell-limit-fokr  r  r  )stopOrderTypeslimitOrderTypes)typesByAccountrM   GFNGLTHEMISGAMECOMHITCHAINPENTASUPERBITCOIN	SOULSAVERBITCOINFILEzFTX Users Debt)	NGLGETGTCHITPNTri  SOULrj  FUD)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingicebergselfTradePreventionleveragemarketBuyByCostmarketBuyRequiresPricemax  x      )r  r  daysBack	untilDayssymbolRequired)r  triggerr  r"  )r  r#  r  r  r"     )r  r#  r  r  r!  r   r"  gUUUUUU?)r  r#  r  r!  r  r   daysBackCanceledr"    )	sandboxr_   r`   r   r   r   r   rq   r   )r  r  r  r     r  )r  r#  r  r  Z   )r  r#  r  r  r   )r  r#  r  r!  r  r   r%    )extendsr_   r`   r   r   r   rq   r   r+  forDerivatives)r   r   )rM   r,  rO   rP   g     @@)commonCurrenciesfeaturesrollingWindowSize)deep_extendsuperr:   describe
userAgentsparse_numberr4   r(   r'   r)   r,   r/   r.   r-   r+   r5   r3   r2   r7   )self	__class__s    F/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/htx.pyr2  zhtx.describe"   s8   c4 0 0 9 9 ; ; i>
%i>
Ei>
 $i>
 	i>

 5i>
 i>
 ti>
 i>
 4i>
  rrr $r 	r
 $r $r Tr $Tr 'r "4r 'r tr r $Ur  r  '!r" /#r r$ ,U%r& 0'r( t)r* +r, (-r. '/r0 &t1r2 (3r4 "45r6 (7r8 -d9r: %d;r<  =r> ?r@  ArB &tCrD +DEr r rF )$GrH &tIrJ #DKrL $TMrN 'OrP (QrR "4SrT UrV &tWrX (YrZ 1$[r\  ]r^ *:_r` +Darb &tcrd #Derf *4gr r rh $Tirj "4krl *5mrn +Dorp #Dqrr "4srt turv #Dwrx  yrz %d{r| $T}r~ /r@ +JArB CrD !$ErF &uGrH  Ir r rJ dKrL $TMrN +DOrP %dQrR !$SrT "4UrV dWrX !$YrZ "4[r\ t]r^ #D_r`  arb 'crd '
erf !$grh (irj (kr r rl %emrn )$orp )$qrr usrt turv wrx Tyrz t{r| "4}r~ #Er@ %dArB &tCrD 'ErF $TGrH !$IrJ )$KrL "4Mr rN %),0 $$('+#!&#'  cr r ri>
z  {i>
R  ~ -+ 7'A&I# #
 (D&I! !
 
 & 3 4023 4!5  /X $    ;]/ /Si>
r  01)* (!0! 3A 21	
 ,Q 6q 23 ( -a .q 0 3A 1! ' #A  .q!" .q#$ 12&'%&,-)*'()*,-+,)*%&9  <*A+Q )! .q	
 ,Q 3A 3A 6q 8 4Q / &q 7 3A $Q  +A!" )!#$ *+()()*+35,./  ?8 8t *+,-,-+,./ *C7 5a *1	
 1! +A +A +C ' ,S 9# 6s ( -a  1!!$ -c%& 23'( 569:*+)*5756-.5  8*A*A -c -c	
 ? =c 9# 3C 1! :1  0!" 1"#$ (%& 3B'( 3A)* 4Q+, .q-. ;<01,.3  ;8 8@ ! 5q$! !&$91("( !&$91("'# # !&$91("( !&$91("'! !%  F   . /  21  <Q	 
 6q  21  1!  8  ;A  9!  9!  @  5a  3A   3A! " -a# $ ,Q% & -.,-45*+01013     <7 137  G7  3A	7 
 9#7  1!7  07  /7  9!7  87  :17  6q7  87  @7 " .q#7 $ *1%7 & 4Q'7 ( 5a)7  7 * 7+7 , :1-7 . 8/7 0 ;B17 2 <Q37 6 2377 8 9#97 : =c;7 < Ec=7 > Fs?7 @ .sA7 B /C7 D 4QE7 F =aG7 J 5aK7 L 5aM7 N 6qO7  7 R 4558:=9:;<@A4545<=3423,-m7  7  7 p1!111! 211! 0	1!
 211! 81! J11! 6q1! 3A1! 5a1! :11! :11! =a1!  ?!1!" ;A#1!$ 22%1!& :2'1!* 4S+1! 1!, 4S-1!. 23/1!0 Fs11!2 Fs31!4 DS51!6 :371!8 >q91!< -a=1!> :1?1!B 3AC1!D 7E1!F 8G1!H /I1!J @K1!L :1M1!N ;AO1!P 5aQ1! 1!R HI78/012:<35a1! 1! 1!sk  k =J JZ  g .g (!g  <Q	g 
 4Qg  =ag  :1g  <Qg  =ag  +Ag  )!g  3Ag  DQg  3Ag  9!g   <Q!g " +A#g $ 3A%g  g & 8'g ( =a)g * ;A+g , @-g . <Q/g 0 81g 2 B13g 4 CA5g 6 A!7g 8 A!9g : 9!;g < 9!=g > I!?g @ A!Ag D =aEg F 5aGg H >qIg  g  g J ;AKg L =aMg N 3AOg P 1!Qg R ;ASg T I!Ug V ;AWg X DQYg Z LQ[g \ A!]g ^ 3A_g ` ;Aag b 9!cg d >qeg f <Qgg h A!ig j =akg  g  g l 9!mg n CAog p DQqg r J1sg t B1ug v B1wg x <Qyg z B1{g | G}g ~ B1g @ MaAg B >qCg F DQGg H <QIg J EaKg L B1Mg N DQOg  g  g P :1Qg R 8Sg T B1Ug V PQRWg X B1Yg Z H[g \ KA]g ^ :1_g ` B1ag b @cg d QRSeg f CAgg h I!ig j Hkg l DQmg n J1og p @qg  g r MNIJKLLMJKJKDEJKOPJKTUUVFGRSMg  g  g iV ;Q  A! 
 =a  B1  DQ  I!  J1  DQ  Fq  STU  KA  STU   1!! " 4Q# $ 6q% & 3A' ( 5a) * 78./120167;<45CD=>;     >n!?n! ;An! <Q	n!
 7n! ?n! DQn! ?n! @n! ?n! Ean! Fqn! :1n! 21n! =an!  =a!n!" DQ#n!$ B1%n! n!& I!'n!( CA)n!* ?+n!, Ea-n!0 ;A1n!2 4Q3n!4 9!5n!6 5a7n!8 89n!: @;n!< >q=n!> 9!?n!@ ;AAn!B 9!Cn!D 8En!F >qGn!H ;AIn! n! n!J A!Kn!L 8Mn!N >qOn!P ;AQn!R A!Sn!V <QWn!X =aYn!Z @[n!\ A!]n!^ @_n!` 9!an!b :1cn!d =aen!f >qgn!h =ain!j B1kn!l :1mn! n! n!n ;Aon!p >qqn!r ?sn!t >qun!x A!yn!z <Q{n!| =a}n!~ Ean!@ 8An!B @Cn!D EaEn!F @Gn!H A!In!J @Kn!L FqMn!N GOn!P DQQn! n! n!R ;ASn!T 3AUn!V >qWn!X >qYn!Z CA[n!\ J1]n!^ @_n!` Fqan!d <Qen!f 5agn!h :1in!j 6qkn!l 9!mn!n Hon!p A"qn!r :1sn!t <Qun! n! n!v :1wn!x 9!yn!z ?{n!| <Q}n!~ B1n!@ <QAn!B B1Cn!D 9!En!F ?Gn!J =aKn!L >qMn!N A!On!P B1Qn!R A!Sn!T :1Un!V ;AWn!X >qYn! n! n!Z ?[n!\ >q]n!^ CA_n!` ;Aan!b <Qcn!d ?en!f @gn!h ?in!l KAmn!n QRSon!p Hqn!r CAsn!t I!un!v DQwn!x J1yn!z LQ{n!| RST}n! n! n!~ ?n!@ GAn!B MaCn!D LQEn!F RSTGn!H GIn!J MaKn!L HMn!N NqOn!P GQn!R MaSn!T NqUn!V TUVWn!X KAYn!Z QRS[n!\ B1]n!^ :1_n! n! n!` Eaan!b KAcn!d Eaen!f KAgn!h J1in!j QRSkn!l Eamn!n Gon!p Maqn!t <Qun!v B1wn!x A!yn!z G{n!| =a}n!~ CAn!@ @An!B FqCn! n! n!D HEn!F NrGn!H OPQIn!J UVWKn!L A!Mn!N GOn!P CAQn!R I!Sn!T A!Un!V GWn!X @Yn!Z Fq[n!\ Fq]n!^ LQ_n!` CAan!b I!cn!d I!en! n! n!f OPQgn!h Eain!j KAkn!l QRSmn!n CAon!p I!qn!r I!sn!t OPQun!v @wn!x Fqyn!z Fq{n!| LQ}n!~ LQn!@ J1An!B HCn!F DQGn!H J1In! n! n!J EaKn!L KAMn!N HOn!P NqQn!R I!Sn!T OPQUn!V HWn!X NqYn!Z A![n!\ G]n!^ B1_n!` Han!b Eacn!d KAen!f Fqgn!h LQin!j Eakn! n! n!l KAmn!n J1on!p PQRqn!r B1sn!t Hun!v CAwn!x I!yn!z Fq{n!| LQ}n!~ Gn!@ MaAn!B FqCn!D LQEn!F 4QGn!H -aIn!J 4QKn!L 4QMn! n!N =>:;12561201AB[n! n! n!AO  O W{ {m	r
 r
si>
X $!&"&!..w77!..w77 Yi>
j ly -1A 
C.C -C /	C
 IC MC LC LC LC LC -C -C MC LC IC  L!C" L#C$ -%C C& J'C( L)C* J+C, ":-C. .z/C0 6z1C2 ,Z3C4 01A5C6 ~7C8 -.B9C: @AR;C< %l=C> 8?C@ 8ACB 9,CCD 7ECF 7GC C CH ;LICJ ;LKCL <\MCN <\OCP 3LQCR ,\SCT *<UCV 1,WCX 7YCZ 4\[C\ -m]C^ /_C` )*>aCb 12EcCd ./BeCf *=gCh 1)iC Cj *3*7;L.?&/1:&/'11;/@/9-7%6EC C CJ Jki>
@ YAi>
B  S)5S $"&#' !S !!S *5S 2DS  %S" v#S$ !(%S& !''S( "" #$ $)S2  U 5 U	
 8 V U 5 5 5 5 e 5 F w  W!" 5#$ F% & F'( 5)* F+, 5-. W/0 512 F34 F56 578 F9: F;<  => F?@ FAB WCD uEF 5G  H 5IJ 5KL 
MN FOP 5QR FST WUV 5WX $YZ 5[\ 5]^ 5_` Wab 5cd 5ef Wgh 5i  j 5kl 5mn 5op 5qr 5st 5uv 6wx Fyz 5{| 5}~ 5@ 5AB FCD FEF FGH 5IJ WK  L 5MN 5OP 5QR 5ST 5UV $WX WYZ 5[\ 5]^ F_` Fab 5cd Fef 5gh 5ij 5kl Fm  n Wop Fqr $st 5uv 5wx 5yz F{| F}~ $@ hAB FCD 5EF 5GH 5IJ $KL 5MN FO  P FQR 5ST 5UV 5WX FYZ F[\ 5]^ 5_` $ab Fcd 5ef Fgh Fij 5kl 5mn Wop 5q  r Fst Fuv Fwx 5yz 5{| 5}~ F@ 7AB FCD 5EF FGH 5IJ 5KL FMN WOP 5QR WS  T FUV FWX 5YZ F[\ 5]^ I_` Fab Wcd 5ef 5gh 
ij 5kl Fmn 5op Fqr Fst 5u  v Fwx yyz F{| 5}~ 5@ FAB 5CD 5EF 5GH 5IJ 7KL 5MN WOP 5QR 5ST 5UV WW X !"[  3St ,-OuSv 4TwSx GySz ,{S@ !!$'# #ASJ "& $$2".&$2'8#0! !KSd "'# # '+*.+/*..2/3' '((#T( %d( t	(
 "4( #D( &t( *4( +D( %d( )$( *4( $T( (( )$(  )$!(" -d#($ .t%( ( kS S SCi>
r&  !
 &#%'!! !(  $&*(,,0,0).+06:#'#'"&#(	( ( #($)#(/3$(+/26)$ $. r% ',!$$'%&*/& & ',#($)*/	# # ',#'$)!$*/( ( ',#'$)!$%&$'*/$ $ ',#'$)%&!$$',2*/	* 	*  #EE EN  &)-+/$("&	$ $ r% %d# '+#($)!#	( ( '+#($)!#$&$ $ '+#($)%&!#$&,2* *  #K(# (#V "#3 "#3 	  "#3 "#3 	 q@ @B "(Q+i>
 i>
 i>
 i i i	    c                     |                                   d}|                     dd|          \  }}|                     ddd          }d}|dk    r|r|                     |d| j        d                   }|dk    r6|d	k    r|                                 }n|d
k    r|                                 }nq|dk    r6|d	k    r|                                 }nP|d
k    r|                                 }n5|dk    r| 	                                }n|dk    r| 
                                }d}d}d}|dk    r<|                     |d          }	|	d}n
|	dk    rdnd}|                     |d          }n|                     |di           }
|                     |
d          }	|	dk    rdnd}|                     |di           }|                     |d          }|                     |          }|                     |d          }||d||dS )a  
        the latest known information on the availability of the exchange API

        https://huobiapi.github.io/docs/spot/v1/en/#get-system-status
        https://huobiapi.github.io/docs/dm/v1/en/#get-system-status
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-system-status
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#get-system-status
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#query-whether-the-system-is-available  # contractPublicGetHeartbeat

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/?id=exchange-status-structure>`
        Nr   enableForContractsFrM   subTyper  rO   r   r   rP   r   r   okmaintenancets	indicatornonepage
updated_atr   )r   updatedetar   info)load_marketshandle_market_type_and_paramshandle_optionsafe_stringr  )statusPublicSwapLinearGetApiV2SummaryJson*statusPublicSwapInverseGetApiV2SummaryJson+statusPublicFutureLinearGetApiV2SummaryJson,statusPublicFutureInverseGetApiV2SummaryJsoncontractPublicGetHeartbeat#statusPublicSpotGetApiV2SummaryJson
safe_value	parse8601)r5  params
marketTypeenabledForContractsresponser;  r   rC  r   	statusRaw
statusDatapageDatadatetimes                r7  fetch_statuszhtx.fetch_status  s`    	
!??tU[\\
F"00@TV[\\$7&&vy$,GW:XYYGV##h&&#MMOOHH	))#NNPPHx''h&&#OOQQHH	))#PPRRHz))::<<6!!??AAHD ##((8<<I "+t"3"3-&&x66GG8R@@J(([AAI'611TTFx<<H'',??HnnX..G""8U33C
 
 	
r8  c                 n   |                      | j        di           }|                     | j        dd          }|                     |d|          }|                     |d|          }d}|dk    s|dk    r|                     |          }n|                     |          }|                     |dd	          S )
a  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://huobiapi.github.io/docs/spot/v1/en/#get-current-timestamp
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-current-system-timestamp

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        r   r  rM   typeNrP   rO   datar>  )rP  r  rI  contractPublicGetApiV1TimestampspotPublicGetV1CommonTimestampsafe_integer_2)r5  rR  r  r  r\  rU  s         r7  
fetch_timezhtx.fetch_timek  s     //$,R@@&&t|]FKK==55H$&..;;FCCHH::6BBH ""8VT:::r8  Nfeemarketc                     |                      |d          }||                     ||          |                     |d          |                     |d          d d dS )NsymbolactualMakerRateactualTakerRate)rE  re  r   r   r   r   )rI  safe_symbolsafe_number)r5  rb  rc  marketIds       r7  parse_trading_feezhtx.parse_trading_fee  sl     ##C22&&x88%%c+<==%%c+<==
 
 	
r8  re  c                 B   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          S )am  
        fetch the trading fees for a market

        https://huobiapi.github.io/docs/spot/v1/en/#get-current-fee-rate-applied-to-the-user

        :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>`
        symbolsr=   r]  r   )rF  rc  (spotPrivateGetV2ReferenceTransactFeeRateextendrP  rk  )r5  re  rR  rc  requestrU  r]  firsts           r7  fetch_trading_feezhtx.fetch_trading_fee  s     	V$$vd|
 @@WV\A]A]^^  x44a,,%%eV444r8  rm  c                     |                                   || j        }i }t          dt          |                    D ]6}||         }|                     |                     |          |          ||<   7|S )Nr   )rF  rm  rangelenfetch_trading_limits_by_id	market_id)r5  rm  rR  resultire  s         r7  fetch_trading_limitszhtx.fetch_trading_limits  s~     	?lGq#g,,'' 	] 	]AQZF!<<T^^F=S=SU[\\F6NNr8  r=   c                     d|i}|                      |                     ||                    }|                     |                     |di                     S )a&  
 @ignore

        https://huobiapi.github.io/docs/spot/v1/en/#get-current-fee-rate-applied-to-the-user

        :param str id: market id
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: the limits object of a market structure
        re  r]  )spotPublicGetV1CommonExchangero  parse_trading_limitsrP  )r5  r=   rR  rp  rU  s        r7  rv  zhtx.fetch_trading_limits_by_id  sY     b
 55dkk'66R6RSS" ((62)N)NOOOr8  c                 f    |d|                      |d          |                      |d          didS )Namountzlimit-order-must-greater-thanzlimit-order-must-less-thanminr  )rE  limits)ri  )r5  r  re  rR  s       r7  r}  zhtx.parse_trading_limits  sP    " ++F4STT++F4PQQ 
 
 	
r8  c                 t    |                      |t          | j        |         d         d         | j                  S )N	precisioncost)decimal_to_precisionr6   marketsr  )r5  re  r  s      r7  cost_to_precisionzhtx.cost_to_precision  s2    ((xf9Mk9Z[a9bdhdvwwwr8  c                 <   | j         d         r|                                  d}|                     |ddi           \  }}g }g }t          |                                          }t          dt          |                    D ]}||         }|                     ||          r|dk    r+|                    | 	                    dd|                     Q|dk    r+|                    | 	                    dd|                     |dk    rT|                    | 	                    d	d|                     |                    | 	                    d
d|                     |}t          dt          |                    D ]}| 
                    |||                   }|S )a   
        retrieves data on all markets for huobi

        https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-trading-symbol-v1-deprecated
        https://huobiapi.github.io/docs/dm/v1/en/#get-contract-info
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-swap-info
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-swap-info

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r  Nr   r  r   rM   r   r   rO   rP   )r  load_time_differencehandle_option_and_paramslistkeysrt  ru  	safe_boolappend"fetch_markets_by_type_and_sub_typearray_concat)r5  rR  r  
allMarketspromisesr  ry  keys           r7  fetch_marketszhtx.fetch_markets
  s    <12 	(%%'''55fngWYZZv
EJJLL!!q#d))$$ 		j 		jAq'C~~eS)) j&==OOD$K$KFTXZ`$a$abbbbH__OOD$K$KDRZ\b$c$cddddI%%OOD$K$KFT]_e$f$fgggOOD$K$KHV_ag$h$hiiiq#h--(( 	D 	DA**:x{CCJJr8  r\  r;  c                    |dk    }i }d}|s|dk    r/d|d<   |                      |                     ||                    }n|dk    r_|dk    r*|                     |                     ||                    }nY|dk    r)|                     |                     ||                    }n)|                     |                     ||                    }|                     |d	g           }t          |          }|d
k     r-t          | j        dz   | 	                    |          z             g }	t          dt          |                    D ]}
||
         }d}d}d}d}d}d|v }| }d}d}d}d}|r|                     |d          }|                                }|                     |d          }|                     |d          }|du}| }|du}| }|rJd}|                    d          }|                     |d          }|                     |d
          }|r|n|}n|rbd}|                     |d          }|rd}|}n|                     |d          }|                    d          }|                     |d
          }|}nGd}|                     |d          }|                     |d          }||z   }|                                }|                     |          }|                     |          }|                     |          }|dz   |z   }d}|rH|r	|d|z   z  }n
|r|d|z   z  }|r1|                     |d          }|d|                     |          z   z  }|                     |d          } |                     |d          }!|                     |d          }"|                     |d          }#|r	|r| }#n|r| }!d}$d}%d}&d}'d}(d})|r|                     |                     |                     |d                              }$|                     |                     |                     |d                              }%|                     |                     |                     |d                              }&|                     d           }'|                     d           }(|                     |d!          }*|*d"k    })nq|                     |d#          }$|                     d$          }%|                     d%          }'|                     d&          }(|                     |d'          }+|+d
k    })|                     |d(d$          },|                     |d)d$          }-t+          j        |,d$          pt+          j        |-d$          }.d}/|                     |d*          }0|0z|                     |0          }1|1d         |1d
         z   |1d+         z   |1d,         z   dz   |1d-         z   |1d.         z   dz   |1d/         z   |1d0         z   d1z   }0|                     |0          }/|	                    i d2|d3|d|d4|d5|d6|d7|d8|d9|d:|d|d;|o|.d|d|d<dd=|)d>||||(|'| ||                     |          dd|%|$|&d?|                     d$          |                     |,          |                     |-          d@|#|"dAdddA|!ddAdB|/|dC           |	S )Da  
 @ignore
        retrieves data on all markets of a certain type and/or subtype

        https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-trading-symbol-v1-deprecated
        https://huobiapi.github.io/docs/dm/v1/en/#get-contract-info
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-swap-info
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-swap-info

        :param str [type]: 'spot', 'swap' or 'future'
        :param str [subType]: 'linear' or 'inverse'
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        rM   Nr   allbusiness_typer   rP   rO   r]  r   z, fetchMarkets() returned an empty response: r   contract_codeFdelivery_date-re  USDpairzbase-currencyzquote-currency/:delivery_timecontract_sizezmin-order-valuezmax-order-amtzmin-order-amtzprice-precisionzamount-precisionzvalue-precisionr   stateonline
price_tick1z0.0002z0.0005contract_statuszleverage-ratiozsuper-margin-leverage-ratiocreate_dater     r   r         z	 00:00:00r=   lowercaseIdbasequotesettlebaseIdquoteIdsettleIdr\  rN   rQ   activer   )r  pricer  )r  r  superMaxr  )r  r  r  r  )r   r   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdrE  )0contractPublicGetLinearSwapApiV1SwapContractInforo  *contractPublicGetApiV1ContractContractInfo*contractPublicGetSwapApiV1SwapContractInfospotPublicGetV1CommonSymbols	safe_listru  r1   r=   jsonrt  rI  lowersplitsafe_string_lowersafe_currency_codesafe_integeryymmddri  r4  parse_precisionr8   	string_gtstring_to_chars_arrayrQ  r  iso8601)2r5  r\  r;  rR  isSpotrp  rU  r  
numMarketsrx  ry  rc  r  r  r  r=   r  r   rM   rO   rP   r   r   r  r  partsr  r  r  r  re  r  r  minCost	maxAmount	minAmountpricePrecisionamountPrecisioncostPrecisionr   r   r  r  contractStatusleverageRatiosuperLeverageRatiohasLeverager  createdDatecreatedArrays2                                                     r7  r  z&htx.fetch_markets_by_type_and_sub_type,  s    &. 
	W(""+0(PPQUQ\Q\]dflQmQmnnI%%8###NNt{{[bdjOkOkllHHV^^#NNt{{[bdjOkOkllH88Wf9U9UVVHn ..6266\\
>>!$',Z"Z]a]f]fgo]p]p"pqqqq#g,,'' a	 a	AQZFFGHBK'61H<DDFFG )%%fo>> hhjj $ 0 0 I I $ 0 0 I I&d2!z&d2$* +!DHHSMME!33FHEEF"44UA>>G)0=vvgHH 
+#D!33FHEEF +"'#)#//?? $

3"&"8"8"B"B#*))&/BB**63CDDg% hhjj**622D++G44E,,X66FCZ%'FF 8 *cDj(FF *cEk)F 8!..vGGFcDKK$7$777F++FODDL&&v/@AAG((AAI((AAI + + ,II +*G!N"O MEEF /!%!2!243G3GHXHXY_arHsHs3t3t!u!u"&"3"3D4H4HIYIYZ`btIuIu4v4v"w"w $ 1 1$2F2FtGWGWX^`qGrGr2s2s t t))'22))'22((998+!%!1!1&,!G!G"&"3"3C"8"8))(33))(33!%!2!26;L!M!M(A- ,,V5EsKKM!%!1!1&:WY\!]!]!+M3??m7CTUgilCmCmK G**6=AAK&#99+FF*1oQ?,q/QT`abTccfiilxyzl{{  K  LM  N  N  QT  T  Wc  de  Wf  f  iu  vw  ix  x  {F  F..55MM 5b5{5 &5 	5
 5 &5 &5 75 H5 5 5 4/K5 5 &5 %5  &!5" H#5$ !" , "&,,v"6"6"-+)   $0055#00??$($5$56H$I$I! !  )( 
  $# 
  '#  & #i5 5 5 5 5 5 5l r8  symbolOrMarketIdc                 V   || j         v r|S d| j        vr
i | j        d<   |                     | j        di           }||v r||         S |                     | j         dd          }ddddd}t	          d	t          |                    D ]}||         }|                     |d
i           }|                     |d          }||         }	|d         r|d         dz   |d         z   dz   |	z   n|d         dz   |	z   }
|
|k    r|d         }|| j        d         |<   |c S || j        d         |<   |S )NfutureMarketIdsForSymbolsrP   TCWNWCQNQ)	this_week	next_weekquarternext_quarterr   rE  contract_typer   r  r  r  _re  )r  r  	safe_dict	filter_byrt  ru  rP  rI  )r5  r  r  futureMarketsfuturesCharsMapsry  rc  rE  contractTypecontractSuffixconstructedIdre  s               r7  "try_get_symbol_from_future_marketsz&htx.try_get_symbol_from_future_marketsH  s   t|++##
 ,t|;;8:DL45$(NN4<A\^`$a$a!888,-=>>t|XtDD 	"
 "
 q#m,,-- 
	 
	A"1%F??66266D++D/BBL-l;N]cdl]m  YF6NS06'?BSH>YYsy  {A  tB  EH  tH  KY  tYM 000)NT89:JK 1
 GW012BCr8  tickerc                    |                      |dd          }|                     ||          }|                     |          }|                     |dd          }d }d }d }d }	d|v r|d         Tt	          |d         t
                    r9|                     |d         d          }|                     |d         d          }n,|                     |d          }|                     |d          }d	|v r|d	         Tt	          |d	         t
                    r9|                     |d	         d          }|                     |d	         d          }	n,|                     |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|          S )Nre  r  r>  	quoteTimebidr   r   bidSizeaskaskSizeopencloser  vol	timestamprY  highlow	bidVolume	askVolumevwaplastpreviousClosechanger   average)
baseVolumequoteVolumerE  )	safe_string_2rh  r  r`  
isinstancer  rI  safe_tickerr  )r5  r  rc  rj  re  r  r  r  r  r  r  r  r  r  s                 r7  parse_tickerzhtx.parse_tickerj  s   \ %%fhHH!!(F3388@@''kBB			F??e}(Zut-L-L(&&ve}a88 ,,VE]A>>		&&vu55 ,,VY??	F??e}(Zut-L-L(&&ve}a88 ,,VE]A>>		&&vu55 ,,VY??	//  11%%fh77
&&vu55 !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 3!
 !
 3!
 !
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r8  c                    |                                   |                     |          }i }d}|d         r5|d         |d<   |                     |                     ||                    }n|d         rz|d         r5|d         |d<   |                     |                     ||                    }nq|d         r4|d         |d<   |                     |                     ||                    }n4|d         |d<   |                     |                     ||                    }|                     |d	i           }|                     ||          }| 	                    |d
          }||d<   | 
                    |          |d<   |S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://huobiapi.github.io/docs/spot/v1/en/#get-latest-aggregated-ticker
        https://huobiapi.github.io/docs/dm/v1/en/#get-market-data-overview
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-market-data-overview
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-market-data-overview

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nr   r=   r  r   rP   re  rO   tickr>  r  rY  )rF  rc  /contractPublicGetLinearSwapExMarketDetailMergedro  #contractPublicGetMarketDetailMerged)contractPublicGetSwapExMarketDetailMergedspotPublicGetMarketDetailMergedrP  r  r  r  )	r5  re  rR  rc  rp  rU  r
  r  r  s	            r7  fetch_tickerzhtx.fetch_ticker  s    	V$$( 	Z'-d|GO$KKDKKX_agLhLhiiHHI 		Zh h$*4L!CCDKKPWY_D`D`aa h+1$<(II$++V]_eJfJfgg &tGH;;DKKQW<X<XYYHX x44""400%%h55	'{!\\)44zr8  c                    |                                   |                     |          }|                     |d          }d}||                     |          }d|v pd|v }d}d}|                     d||          \  }}|                     d||          \  }}i }|dk    }	|dk    }
|dk    }|d	k    }|d
k    }d}|	r|r|r?|
rd|d<   n|rd|d<   nd|d<   |                     |                     ||                    }n|ro|
r*|                     |                     ||                    }n|r*| 	                    |                     ||                    }nWt          | j        dz             t          | j        dz             |                     |                     ||                    }|                     |ddg           }|                     |||          }|                     |d|          S )aG  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://huobiapi.github.io/docs/spot/v1/en/#get-latest-tickers-for-all-pairs
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-a-batch-of-market-data-overview
        https://huobiapi.github.io/docs/dm/v1/en/#get-a-batch-of-market-data-overview
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-a-batch-of-market-data-overview-v2

        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>`
        r   Nr;  r  r   rM   rP   rO   r   r   r  r  za fetchTickers() you have to set params["type"] to either "swap" or "future" for inverse contractsz_ fetchTickers() you have to set params["subType"] to either "linear" or "inverse" for contractsr]  ticksre  )rF  market_symbolsrI  rc  rG  handle_sub_type_and_params4contractPublicGetLinearSwapExMarketDetailBatchMergedro  (contractPublicGetMarketDetailBatchMerged.contractPublicGetSwapExMarketDetailBatchMergedr0   r=   spotPublicGetMarketTickerssafe_list_2parse_tickersfilter_by_array_tickers)r5  rm  rR  rq  rc  isSubTypeRequestedr\  r;  rp  r  rP   rO   r   r   rU  
rawTickerstickerss                    r7  fetch_tickerszhtx.fetch_tickers	  s    	%%g..  !,,[[''F'61Q&7P99.&RXYYf99.&RXYY&.("X%i' 	U+ 	U P 5/8GO,, 5/5GO,,/4GO,TTUYU`U`ahjpUqUqrr P V#LLT[[Y`bhMiMijjHH V#RRSWS^S^_fhnSoSoppHH&tw  2U  (U  V  V  V"47  .O  $O  P  P  P66t{{7F7S7STTHf %%hDD
$$Z&AA++GXwGGGr8  c                    |                                   |                     |          }|                     |          }d}d}|                     d||          \  }}|                     d||          \  }}d}|dk    s|dk    r|dk    r|                     |          }na|dk    r|dk    r|                     |          }n?|dk    r|dk    r|                     |          }nt          | j	        dz   |z   dz             | 
                    |d	i           }|                     |d
g           }|                     ||          S )ax  
        fetches the last price for multiple markets

        https://www.htx.com/en-us/opend/newApiPages/?id=8cb81024-77b5-11ed-9966-0242ac110003 linear swap & linear future
        https://www.htx.com/en-us/opend/newApiPages/?id=28c2e8fc-77ae-11ed-9966-0242ac110003 inverse future
        https://www.htx.com/en-us/opend/newApiPages/?id=5d517ef5-77b6-11ed-9966-0242ac110003 inverse swap

        :param str[] [symbols]: unified symbols of the markets to fetch the last prices
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of lastprices structures
        Nr   rO   rP   r   r   z$ fetchLastPrices() does not support z markets yetr
  r]  )rF  r  get_market_from_symbolsr  rG  (contractPublicGetLinearSwapExMarketTrade"contractPublicGetSwapExMarketTradecontractPublicGetMarketTrader0   r=   rP  r  parse_last_prices)	r5  rm  rR  rc  r\  r;  rU  r
  r]  s	            r7  fetch_last_priceszhtx.fetch_last_prices	  sq    	%%g..--g6699:KVU[\\99:KVU[\\fV^^!1!1H9L9LDDVLLHH4 fnn7i#7#7>>vFFHH. hW	%9%988@@HH0 tw)OORVVYgghhhx44~~dFB//%%dG444r8  c                     |                      |dd          }|                     ||          }|                     |d          }|                     |d          }|d         d d |||dS )Nre  r  r  	direction)re  r  rY  r  siderE  )r  safe_marketri  rI  )r5  entryrc  rj  r  r'  s         r7  parse_last_pricezhtx.parse_last_price	  s    %%eXGG!!(F33  00$$UK88	 X&
 
 	
r8  r  c                 p   |                                   |                     |          }ddi}d}|d         r5|d         |d<   |                     |                     ||                    }n|d         rz|d         r5|d         |d	<   |                     |                     ||                    }n|d
         r4|d         |d<   |                     |                     ||                    }np|:|dk    r)|dk    r#|dk    r|dk    rt          | j        dz             |dk    r||d<   |d         |d	<   |                     |                     ||                    }d|v r|d         s-t          | j        dz   | 
                    |          z             |                     |d          }|                     |d|                     |d                    }|                     |||          }	|                     |d          |	d<   |	S t          | j        dz   | 
                    |          z             )a   
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://huobiapi.github.io/docs/spot/v1/en/#get-market-depth
        https://huobiapi.github.io/docs/dm/v1/en/#get-market-depth
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-market-depth
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-market-depth

        :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\  step0Nr   r=   r  r   rP   re  rO   r   r         zP fetchOrderBook() limit argument must be None, 5, 10, 20, or 150, default is 150depthr
  z+ fetchOrderBook() returned empty response: r>  rG   noncez2 fetchOrderBook() returned unrecognized response: )rF  rc  (contractPublicGetLinearSwapExMarketDepthro  contractPublicGetMarketDepth"contractPublicGetSwapExMarketDepthr+   r=   spotPublicGetMarketDepthr,   r  rP  r  parse_order_bookr&   )
r5  re  r  rR  rc  rp  rU  r
  r  rx  s
             r7  fetch_order_bookzhtx.fetch_order_book	  s{    	V$$ G

 ( 	S'-d|GO$DDT[[QXZ`EaEabbHHI 	Sh a$*4L!<<T[[RX=Y=YZZ a+1$<(BB4;;wX^C_C_`` QJJUb[[u{{RU$TW  0B  &B  C  C  C C<<',GG$ &tGH44T[[&5Q5QRRH6 XF# o*W WZ^ZcZcdlZmZm mnnn??8V44D))$d6G6GRV6W6WXXI**4CCF"//i@@F7OMDG&ZZ]a]f]fgo]p]ppqqqr8  tradec                 0   |                      |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          }|F|t          j	        |d          r/|                     |d          }||}|                     |          }|||d}d }|                     |d          }||
                    d          dk    r|}n|                     |g d          }|                     |||||                     |          ||||
||||d|          S ) Nr  re  r>  
created-at
created_atr  order-idorder_idr'  r\  r  r   r   roler  trade_pricefilled-amountr  trade_volumetrade_turnoverfilled-fees	trade_feezfee-currency	fee_assetzfilled-points0zfee-deduct-currencyr  currencyr=   )trade_idztrade-idr=   )r=   rE  orderr  rY  re  r\  r(  takerOrMakerr  r  r  rb  )r  r)  r`  rI  r  r  r8   
string_negr  string_equalsfindsafe_string_n
safe_trader  )r5  r8  rc  rj  re  r  rJ  r(  r\  	typePartsrK  priceStringamountString
costStringrb  feeCostfeeCurrencyIdfeeCurrencyfilledPointsfeeDeductCurrencyr=   safeIds                         r7  parse_tradezhtx.parse_tradeN
  s   ^ %%e_hGG!!(F33!''t\BB	''|]IVV	""5*jAA{33v..

3IQ<DQ<D--eV<<((GG))%(KK''~|LL%%e-=>>
""5-88?()9)9%)M)MNNG**5.+NN--m<<''??#G$9'3$G$G$($4$4U<Q$R$R!$0*G"&"9"9:K"L"LK' C !!%..&++c"2"2a"7"7BB##E+I+I+IJJB"Y//( " 
  
   	r8  sincec                     d}||                      |          }d}|                     d||          \  }}|dk    rt          | j        dz             |                     |||||          S )a+  
        fetch all the trades made from a single order

        https://huobiapi.github.io/docs/spot/v1/en/#get-the-match-result-of-an-order

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nr   rM   z6 fetchOrderTrades() is only supported for spot markets)rc  rG  r0   r=   fetch_spot_order_trades)r5  r=   re  r\  r  rR  rc  rS  s           r7  fetch_order_tradeszhtx.fetch_order_trades
  s     [[((F
!??@RTZ\bcc
Ftw)aabbb++BufMMMr8  c                     |                                   d|i}|                     |                     ||                    }|                     |d         d||          S )a4  
 @ignore
        fetch all the trades made from a single order

        https://huobiapi.github.io/docs/spot/v1/en/#get-the-match-result-of-an-order

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        r<  r]  N)rF  .spotPrivateGetV1OrderOrdersOrderIdMatchresultsro  parse_trades)r5  r=   re  r\  r  rR  rp  rU  s           r7  r^  zhtx.fetch_spot_order_trades
  sf     	
 FFt{{SZ\bGcGcdd  &!14FFFr8  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S d}||                     |          }d}|                     d||          \  }}i }d}	|dk    ru| |                     |          }|d         |d<   |||d<   |||d	<   |                     d
||          \  }}|                     |                     ||                    }	nj|t          | j	        dz             |d         |d<   d|d<   |||d<   |                     d||          \  }}|||d<   |d         rd}
| 
                    d|          \  }
}|
dn|
}
|
dk    r*|                     |                     ||                    }	n|
dk    r)|                     |                     ||                    }	n|d         r|dk    r5|d         |d<   |                     |                     ||                    }	nM|dk    r*|                     |                     ||                    }	nt          | j	        dz   |z   dz             |                     |	d          }t#          |t$                    s|                     |d          }|                     ||||          S )a#  

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-get-history-match-results-via-multiple-fields-new
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-get-history-match-results-via-multiple-fields-new
        https://huobiapi.github.io/docs/spot/v1/en/#search-match-results

        fetch all trades made by the user
        :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 int [params.until]: the latest time in ms to fetch trades for
        :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 Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Fr   paginateNrM   r=   re  size
start-timeend-timez+ fetchMyTrades() requires a symbol argumentr   r   
trade_type
start_timeend_time	page_sizer   crossisolatedr   rP   r  rO   z" fetchMyTrades() does not support  marketsr]  trades)rF  r  fetch_paginated_call_dynamicrc  rG  handle_until_option!spotPrivateGetV1OrderMatchresultsro  r*   r=   handle_margin_mode_and_params7contractPrivatePostLinearSwapApiV3SwapMatchresultsExact<contractPrivatePostLinearSwapApiV3SwapCrossMatchresultsExact1contractPrivatePostApiV3ContractMatchresultsExact1contractPrivatePostSwapApiV3SwapMatchresultsExactr0   rP  r  r  rb  )r5  re  r\  r  rR  rd  rc  rS  rp  rU  r  ro  s               r7  fetch_my_tradeszhtx.fetch_my_trades  sC     	88R\]]& 	d44_feUZ\bccc[[((F
!??QWY_``
F
& !V,,$*4L! "' (-%"66z7FSSOGV==dkk'SY>Z>Z[[HH~'2_(_```"(,GJ$%GL! (-%"66z7FSSOGV ',$h q!
%)%G%GY_%`%`"
F)3);WW*
++#[[\`\g\ghoqw\x\xyyHH7**#``aealalmtv|a}a}~~H	" q))(.z(:GH%#UUVZVaVabikqVrVrssHH6))#UUVZVaVabikqVrVrssHH&tw1U'UXb'beo'opppF 622&$'' 	7__VX66F  >>>r8  r&  c                    |                                   |                     |          }i }|t          |d          |d<   d}|d         rz|d         r5|d         |d<   |                     |                     ||                    }n|d         r4|d         |d	<   |                     |                     ||                    }n|d
         ro|d         |d	<   |d         r*|                     |                     ||                    }nf|d         r)|                     |                     ||                    }n4|d         |d<   |                     |                     ||                    }|                     |dg           }g }	t          dt          |                    D ]p}
|                     ||
         dg           }t          dt          |                    D ]3}|                     ||         |          }|	                    |           4q|                     |	d          }	|                     |	|d         ||          S )ah  

        https://huobiapi.github.io/docs/spot/v1/en/#get-the-most-recent-trades
        https://huobiapi.github.io/docs/dm/v1/en/#query-a-batch-of-trade-records-of-a-contract
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-a-batch-of-trade-records-of-a-contract
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-a-batch-of-trade-records-of-a-contract

        get the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nr*  re  rP   r   r=   re  r   r  rO   r]  r   r  )rF  rc  r  #contractPublicGetMarketHistoryTradero  /contractPublicGetLinearSwapExMarketHistoryTrade)contractPublicGetSwapExMarketHistoryTradespotPublicGetMarketHistoryTraderP  rt  ru  r[  r  sort_byfilter_by_symbol_since_limit)r5  re  r\  r  rR  rc  rp  rU  r]  rx  ry  ro  jr8  s                 r7  fetch_tradeszhtx.fetch_trades  sn    	V$$
 !%..GFO( 	Zi  n$*4L!CCDKKPWY_D`D`aa! n+1$<(OOPTP[P[\cekPlPlmmF^ 	Z'-d|GO$i  nII$++V]_eJfJfgg! nOOPTP[P[\cekPlPlmm &tGH;;DKKQW<X<XYYH2 x44q#d))$$ 	% 	%A__T!Wfb99F1c&kk** % %((F;;e$$$$% fk22009I5RWXXXr8  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr=   r  r  r  r  r  )safe_timestampri  )r5  ohlcvrc  s      r7  parse_ohlcvzhtx.parse_ohlcv  s     t,,UF++UF++UE**UG,,UH--
 	
r8  r   	timeframec           	         |                                   d}|                     |dd          \  }}|r|                     d|||||d          S |                     |          }d|                     | j        ||          i}|                     |ddg          }	|                     |ddg          }d}
|                     |d	          \  }
}|
| 	                    |
dz            nd}|d
         r|t          |d          |d<   nd}|	|                     |          }d}|%|                                 }|||dz
  z  z
  |d<   |}n9| 	                    |dz            }||d<   |                     |||dz
  z            }||n||d<   d}|d         r|d         r|d         |d<   |	dk    r+|                     |                     ||                    }n|	dk    r+|                     |                     ||                    }n|	dk    r)t#          | j        dz   |d         z   dz   |	z   dz             |                     |                     ||                    }n4|d         r|d         |d<   |	dk    r+|                     |                     ||                    }n|	dk    r)t#          | j        dz   |d         z   dz   |	z   dz             |	dk    r+|                     |                     ||                    }n|                     |                     ||                    }ne|d         r|d         |d<   |d         r|	dk    r+|                     |                     ||                    }n|	dk    r)t#          | j        dz   |d         z   dz   |	z   dz             |	dk    r+|                     |                     ||                    }n|                     |                     ||                    }n|d         r|	dk    r+|                     |                     ||                    }nT|	dk    r)t#          | j        dz   |d         z   dz   |	z   dz             |	dk    r*|                     |                     ||                    }n|                     |                     ||                    }n|d         |d<   d}|                     |ddd          \  }}|s?|t          |d          |d<   |                     |                     ||                    }nb|| 	                    |dz            |d<   |||d<   |t          d|          |d<   |                     |                     ||                    }|                     |d g           }|                     |||||          S )!a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://huobiapi.github.io/docs/spot/v1/en/#get-klines-candles
        https://huobiapi.github.io/docs/dm/v1/en/#get-kline-data
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-kline-data
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-kline-data

        :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 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)
        :param str [params.useHistoricalEndpointForSpot]: True/false - whether use the historical candles endpoint for spot markets or default klines endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fr   rd  r&  period	priceTyper  Nuntilr   r*  re  r   fromtorP   r   r=   re  markindexpremiumIndex r\  z has no api endpoint for z kline datar   r  rO   r  Tr]  )rF  r  "fetch_paginated_call_deterministicrc  rI  r   rO  omithandle_param_integerparse_to_intr  parse_timeframesecondssum1contractPublicGetIndexMarketHistoryMarkPriceKlinero  (contractPublicGetIndexMarketHistoryIndexr+   r=   #contractPublicGetMarketHistoryKline;contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline>contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline/contractPublicGetLinearSwapExMarketHistoryKline5contractPublicGetIndexMarketHistorySwapMarkPriceKline8contractPublicGetIndexMarketHistorySwapPremiumIndexKline)contractPublicGetSwapExMarketHistoryKlinespotPublicGetMarketHistoryKline!spotPublicGetMarketHistoryCandlesr  parse_ohlcvs)r5  re  r  r\  r  rR  rd  rc  rp  r  r  untilSecondsdurationcalcualtedEndnowstartrU  useHistoricalr]  s                      r7  fetch_ohlcvzhtx.fetch_ohlcv  s   $ 	88zZZ& 	x::<QVX]_hjprvwwwV$$d&&t	9MM
 &&vW/EFF	6K#9::11&'BBv;@;Lt((666SW* 	^ "%eT"2"2  //	:: $=,,..C&)H	,B&BGFO$'MM --edl;;E&+GFO$(HHUH	4J$K$KM1=1IP]( 9	`i  r$*4L!&&#UUVZVaVabikqVrVrssHH'))#LLT[[Y`bhMiMijjHH.00$TWs]VF^%CFa%adm%mp}%}~~~#GGT[]cHdHdeeHH! 	r+1$<(&&#__`d`k`klsu{`|`|}}HH'))$TWs]VF^%CFa%adm%mp}%}~~~.00#bbcgcncnovx~cc   A   AHH#SSTXT_T_`gioTpTpqqHF^ $	`'-d|GO$i  r&&#YYZ^ZeZefmouZvZvwwHH'))$TWs]VF^%CFa%adm%mp}%}~~~.00#\\]a]h]hiprx]y]yzzHH#MMdkkZaciNjNjkkHH! r&&#__`d`k`klsu{`|`|}}HH'))$TWs]VF^%CFa%adm%mp}%}~~~.00#bbcgcncnovx~cc   A   AHH#SSTXT_T_`gioTpTpqqH &tGH M$($A$A&,Xvx|$}$}!M6  `$&)%&6&6GFO??GU[@\@\]] $&*&7&7&E&EGFO+$0GDM$&)$&6&6GFOAA$++gW]B^B^__ ~~h33  vy%GGGr8  c                     |                                   |                     |          }|                     |d          }|                     |          S )ax  
        fetch all the accounts associated with a profile

        https://huobiapi.github.io/docs/spot/v1/en/#get-all-accounts-of-the-current-user

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/?id=account-structure>` indexed by the account type
        r]  )rF  spotPrivateGetV1AccountAccountsrP  parse_accountsr5  rR  rU  r]  s       r7  fetch_accountszhtx.fetch_accounts  sR     	77?? x00""4(((r8  c                     |                      |d          }|                     | j        di           }|                     |||          }||                      |d          |d dS )Nr\  r  r=   )rE  r=   r\  code)rI  rP  r  )r5  accounttypeIdr  r\  s        r7  parse_accountzhtx.parse_account  sp     !!'622t|^RHH|VV<<""7D11	
 
 	
r8  r  c                 v   |                                  }|                     |dd          }||S |dk    r|dk    rd}n|dk    rd}d}||                     |          }t          d	t	          |                    D ]}||         }	|                     |	d
          }
|                     |
dd          }|                     |	d          }|dk    r||k    r|                     |	d          c S r||k    r|                     |	d          c S |                     |d	i           }|                     |d          S )a2  
        fetch all the accounts by a type and marginModeassociated with a profile

        https://huobiapi.github.io/docs/spot/v1/en/#get-all-accounts-of-the-current-user

        :param str type: 'spot', 'swap' or 'future
        :param str [marginMode]: 'cross' or 'isolated'
        :param str [symbol]: unified ccxt market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/?id=account-structure>` indexed by the account type
        	accountId
account-idNrM   rl  r  rm  rN   r   rE  subtyper\  r=   )load_accountssafe_value_2rw  rt  ru  rP  rI  )r5  r\  r  re  rR  accountsr  rj  ry  r  rE  r  typeFromAccountdefaultAccounts                 r7  fetch_account_id_by_typezhtx.fetch_account_id_by_type  st    %%''%%fk<HH	 6>>W$$%z))~~f--Hq#h--(( 		7 		7AqkG??7F33D&&tY==G"..w??Oxh&&++GT::::: '((''66666 )1b99555r8  c                    |                      |          }|                     |dg           }i }i | j        d<   i | j        d<   t          dt	          |                    D ])}||         }|                     |d          }|                     |          }|                     |d          }	|	dk    }
i | j        d         |<   |                     |d
g           }i }t          dt	          |                    D ]E}||         }|                     |d          }|                     |dd          }|| j        d         |         |<   || j        d         |<   |                     |          }|||| 	                    |d          dd| 	                    |d          | 	                    |d          ddd|                     |d          dk    |                     |d          dk    | 	                    |d          | 
                    |                     |                     |d                              d	||<   G|                     ||||                     |d          dk    dddd|
ddddddddddd|d          ||<   +|S )a%  
        fetches all available currencies on an exchange

        https://huobiapi.github.io/docs/spot/v1/en/#apiv2-currency-amp-chains

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r]  networkChainIdsByNamesnetworkNamesByChainIdsr   rH  	assetTyper  cryptofiatchainschain	baseChaindisplayNameminDepositAmtNr  minWithdrawAmtmaxWithdrawAmt)depositr   depositStatusallowedwithdrawStatustransactFeeWithdrawwithdrawPrecision)	rE  r=   networkr  r  r  r   rb  r  
instStatusnormal)r  r   r  )rE  r  r=   r  r  r   rb  r>   r\  r  r  r'  )"spotPublicGetV2ReferenceCurrenciesr  r  rt  ru  rI  r  r  network_id_to_coderi  r4  r  safe_currency_structure)r5  rR  rU  r]  rx  ry  r*  
currencyIdr  r  r\  r  r'  r  
chainEntryuniqueChainIdtitlenetworkCodes                     r7  fetch_currencieszhtx.fetch_currencies  s    ::6BBJ ~~h3313-.13-.q#d))$$ >	 >	AGE))%<<J**:66D((<<I(D;=DL1248^^E8R88FH1c&kk**  #AY
 $ 0 0W E E**:{MRRFS56t<UCHM56}E"55mDD&'* $(#3#3J#P#P#'$ $
 $(#3#3J@P#Q#Q#'#3#3J@P#Q#Q% %	 	 ##//
OLLPYY $ 0 0=M N NR[ [++J8MNN!%!2!243G3GHXHXYcexHyHy3z3z!{!{%) )%%(  77 **5,??8K   $# 
  $#! !
  $#     "$39 9  F4LL6 r8  	networkIdcurrencyCodec                 H   t          | j        d                                                   }t          |          }|dk    rt	          | j        dz             |                     | j        d         ||          }t          t          |           	                    |          S )Nr  r   z7 networkIdToCode() - markets need to be loaded at first)
r  r  r  ru  r&   r=   rP  r1  r:   r  )r5  r  r  r  
keysLengthnetworkTitler6  s         r7  r  zhtx.network_id_to_codeB  s    DL!9:??AABBYY
??*c cdddt|4L'MyZcddS$22<@@@r8  r  c                    |t          | j        dz             t          | j        d                                                   }t          |          }|dk    rt          | j        dz             |                     | j        d         |i           }||v r||         S t          t          |           
                    |          }|                     |||          S )Nz3 networkCodeToId() requires a currencyCode argumentr  r   z7 networkCodeToId() - markets need to be loaded at first)r*   r=   r  r  r  ru  r&   rP  r1  r:   network_code_to_id)r5  r  r  r  r  uniqueNetworkIdsr  r6  s          r7  r  zhtx.network_code_to_idK  s    #DG.c$cdddDL!9:??AABBYY
??*c cddd??4<8P+QS_acdd***#K00 d++>>{KKL??#3\<PPPr8  c                    |                                   d}|                     dd|          \  }}d}d}d}|                     |dddd          \  }}|                     |dddd          \  }}|                     |dd	d          \  }}i }|d
k    }|dk    }|dk    }	|dk    }
d}|                     d|          \  }}|dk    }|dk    }|dk    p|o|p|}d}|r+|                     |                     ||                    }n|s|r|rX|r+|                     |                     ||                    }na|                     |                     ||                    }n6| 	                                 | 
                    |dd|          }||d<   |                     |                     ||                    }n|r*|                     |                     ||                    }n|
rV|r*|                     |                     ||                    }n|                     |                     ||                    }nW|	rU|r*|                     |                     ||                    }n)|                     |                     ||                    }d|i}|                     |d          }|r|                     |dg           }t'          dt)          |                    D ]g}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |||<   h|                     |          }nX|s|r|rt'          dt)          |                    D ]}||         }|                     |                     |d                    }|                     |d          }i }t'          dt)          |                    D ]O}||         }|                     |d          }|                     |          }|                     |||          ||<   P|                     |          ||<   ѐna|                     |dg           }t'          dt)          |                    D ]O}||         }|                     |d          }|                     |          }|                     |||          ||<   P|                     |          }n|rWt'          dt)          |                    D ]6}||         }|                     |d          }|                     |          }|r|                     |di           } t'          dt)          |                     D ]h}| |         }|                     |d          }!||                     |d          d}"|                     |!          }|"||<   |                     |          }i|                                 }|                     |d          |d<   |                     |d           |d!<   |||<   |                     |          }8nl|
r|                     |di           }#|rt'          dt)          |                    D ]}||         }|                     |dd"          }!|                     |!          }$|                     |d          }|                     |          }%|                     |$d#|%d$                   }|m|                                 }|                     |d%          |d<   |                     |d           |d!<   i }&||&|<   |$d         }|                     |&          ||<   nB|                                 }|                     |#d          |d<   |                     |#d%          |d&<   |                     |#dd          }|                     |          }|||<   |                     |          }n|	rt'          dt)          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d           |d!<   |||<   |                     |          }|S )'a4  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://huobiapi.github.io/docs/spot/v1/en/#get-account-balance-of-a-specific-account
        https://www.htx.com/en-us/opend/newApiPages/?id=7ec4b429-7773-11ed-9966-0242ac110003
        https://www.htx.com/en-us/opend/newApiPages/?id=10000074-77b7-11ed-9966-0242ac110003
        https://huobiapi.github.io/docs/dm/v1/en/#query-asset-valuation
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-user-s-account-information
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-query-user-s-account-information
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-query-user-39-s-account-information
        https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19588469969

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: linear or future
        :param bool [params.uta]: provide self parameter if you have a recent account with unified cross+isolated margin account
        :param bool [params.multiAssetMode]: set to True if you are using multi-asset mode for USDT-margined contracts
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        Nrj   r  r;  r   unifiedutaFmultiAssetModerM   rP   r   rm  rl  rN   r  rE  r]  detailsr   rH  withdraw_availablefreere  r  margin_assetisolated_swapr  margin_available)r  r  margin_staticmargin_frozenusedmargin_accountr  r  margin_balancetotal)rF  rG  handle_option_and_params_2r  rs  "contractPrivateGetV5AccountBalancero  %spotPrivateGetV1MarginAccountsBalance*spotPrivateGetV1CrossMarginAccountsBalancer  r  /spotPrivateGetV1AccountAccountsAccountIdBalance3contractPrivateGetLinearSwapApiV3UnifiedAccountInfo1contractPrivatePostLinearSwapApiV1SwapAccountInfo6contractPrivatePostLinearSwapApiV1SwapCrossAccountInfo+contractPrivatePostApiV1ContractAccountInfo+contractPrivatePostSwapApiV1SwapAccountInforP  r  rt  ru  rI  r  r  safe_balancerh  parse_margin_balance_helperri  r  r)  safe_currency)'r5  rR  r\  r;  isUnifiedAccountisMultiAssetModerp  rM   rP   r   r   r  rm  rl  rN   rU  r  rx  r]  r  ry  balancer  r  r  r*  re  balances	subResultr  marginAssetr  r  rj  
subBalancerq  rc  rH  accountsByCodes'                                          r7  fetch_balancezhtx.fetch_balanceY  s	   & 	99.$PVWWf99&.Rbdmowxx#'#B#B6>[dfkmr#s#s &#'#@#@Yikp#q#q &("i'X%
!??PVWW
F*,w&("E(D%2C8 	j>>t{{7TZ?[?[\\HH 	jV 	j 	n m#II$++V]_eJfJfggHH#NNt{{[bdjOkOkllHH""$$$ 99$dFSS	(1%OOPTP[P[\cekPlPlmm 	jOOPTP[P[\cekPlPlmmHH 		j uQQRVR]R]^egmRnRnooVVW[WbWbcjlrWsWstt 	j jKKDKKX_agLhLhiiKKDKKX_agLhLhiiL )x00 \	/nnT9b99G1c'll++ ' '!!*!--gzBB
..z::,,.."&"2"27<P"Q"Q&t&&v..FF R	/V R	/ 3q#d)),, 
B 
BA GE!--d.>.>uh.O.OPPF#uf==H&(I"1c(mm44 e e"*1+%)%5%5gz%J%J
#66zBB*.*J*J7TXZc*d*d	$%)%6%6y%A%AF6NN
B  ??4<<q#h--00 [ [A&qkG!%!1!1':!F!FJ22:>>D#'#C#CGTSY#Z#ZF4LL**622 =	/1c$ii(( 7 7Q"..unEE#66{CC 7$(OOE?B$O$OM"1c-&8&899 	; 	;"/"2#'#3#3G_#M#M$0$($4$4W>P$Q$Q, ,
 "&!1!1(!;!;)3v!%!2!26!:!:	; #llnnG&*&6&6uo&N&NGFO&*&6&6uo&N&NGFO+2F<(!..v66FF+7,  &	/OOD!R00E 3q#d)),, K KA"1gG#11'?L\]]H!--h77F!%!1!1'>!J!JJ#11*==H++FHhv>NOOD '"&,,..*.*:*:7DT*U*U*.*:*:7O*T*T/1/6t,!'!1)-):):>)J)Jv#K& ,,.."&"2"25:N"O"O#'#3#3E;K#L#L !//~xPP
..z::&t**622 		/1c$ii(( ' 'q'!--gx@@
..z::,,.."&"2"27<N"O"O"&"2"27O"L"L&t&&v..Fr8  c                 ,   |                                   d}||                     |          }d}|                     d||          \  }}i }d}|dk    rs|                     |d          }|+|                     |                     ||                    }n||d<   |                     |                     ||                    }ny|t          | j        dz             | 	                    |dd          }|||d<   n||d<   | 
                    |ddg          }|d	         |d
<   |d         rd}	|                     d|          \  }	}|	dn|	}	|	dk    r*|                     |                     ||                    }n|	dk    r)|                     |                     ||                    }n|d         r|dk    r5|d         |d<   |                     |                     ||                    }nM|dk    r*|                     |                     ||                    }nt!          | j        dz   |z   dz             |                     |d          }
t%          |
t&                    r|                     |
d          }
|                     |
          S )a  
        fetches information on an order made by the user

        https://huobiapi.github.io/docs/spot/v1/en/#get-the-order-detail-of-an-order-based-on-client-order-id
        https://huobiapi.github.io/docs/spot/v1/en/#get-the-order-detail-of-an-order
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-get-information-of-an-order
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-get-information-of-order
        https://huobiapi.github.io/docs/dm/v1/en/#get-information-of-an-order
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-information-of-an-order

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   rM   clientOrderIdr<  z( fetchOrder() requires a symbol argumentclient_order_idr=  r=   r  r   rl  rm  r   rP   r  re  rO   z fetchOrder() does not support rn  r]  r   )rF  rc  rG  rI  )spotPrivateGetV1OrderOrdersGetClientOrderro  "spotPrivateGetV1OrderOrdersOrderIdr*   r=   r  r  rs  /contractPrivatePostLinearSwapApiV1SwapOrderInfo4contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo)contractPrivatePostApiV1ContractOrderInfo)contractPrivatePostSwapApiV1SwapOrderInfor0   rP  r  r  parse_order)r5  r=   re  rR  rc  rS  rp  rU  r  r  rJ  s              r7  fetch_orderzhtx.fetch_order  s     	[[((F
!??fV\]]
F
  ,,V_EEM(  II$++V]_eJfJfgg&(
#BB4;;wX^C_C_``~'2\(\]]] ..v7H/ZZM$&(
##-:)*6,=+OPP'-d|GO$h n!
%)%G%GV\%]%]"
F)3);WW*
++#SSTXT_T_`gioTpTpqqHH7**#XXY]YdYdelntYuYuvvH	" n))(.z(:GH%#MMdkkZaciNjNjkkHH6))#MMdkkZaciNjNjkkHH&tw1R'RU_'_bl'lmmm| &11eT"" 	.OOE1--E&&&r8  c                     d }||v r	||         }n|                                  }|d         dk    r|                     |d          |d<   |d         dk    r|                     |d          |d<   |S )Nr\  r8  r  r  frozenr  )r  rI  )r5  r  r  rx  r  s        r7  r  zhtx.parse_margin_balance_helper  s}    6>>TlGGllnnG6?g%%"..w	BBGFO6?h&&"..w	BBGFOr8  c                    |                      | j        dd          }|dk    r|t          | j        dz             |                                  d }d|i}| |                     |          }|d         |d<   |||d<   |                     |d          |d	<   |                     d	||          \  }}|||d
<   d }	|dk    r*|                     | 	                    ||                    }	n)| 
                    | 	                    ||                    }	|                     |	dg           }
|                     |
|||          S )Nr  r  z) fetchOrders() requires a symbol argumentstatesr=   re  rf  i L
rg  re  r]  )rI  r  r*   r=   rF  rc  r  rq  spotPrivateGetV1OrderOrdersro  spotPrivateGetV1OrderHistoryr  parse_orders)r5  r  re  r\  r  rR  methodrc  rp  rU  r]  s              r7  fetch_spot_orders_by_stateszhtx.fetch_spot_orders_by_states  si   !!$,0KMopp777~'2](]^^^ f
" [[((F &tGH$)GL!"&((52E"F"FGJ22:wOO#GFO77777GV8T8TUUHH88Wf9U9UVVH6 ~~h33  vue<<<r8  c                 4    |                      d||||          S )NzGpre-submitted,submitted,partial-filled,filled,partial-canceled,canceledr  r5  re  r\  r  rR  s        r7  fetch_spot_orderszhtx.fetch_spot_orders  s<    //0y  |B  DI  KP  RX  Y  Y  	Yr8  c                 4    |                      d||||          S )Nz filled,partial-canceled,canceledr!  r"  s        r7  fetch_closed_spot_orderszhtx.fetch_closed_spot_orders  s#    //0RTZ\achjpqqqr8  c                    |t          | j        dz             |                                  |                     |          }ddd}d }|                     |dd          }|                     |d          }	|                     |dd	          }
|                     |g d
          }|s|	s|
r|||d<   |d         |d<   d|d<   n|||d<   |d         |d<   d|d<   |                     d||          \  }}|d         rd }| 	                    d|          \  }}|dn|}|dk    r|r+| 
                    |                     ||                    }n|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }nd|                     |                     ||                    }n9|dk    r|r+|                     |                     ||                    }n|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }n|                     |                     ||                    }n|d         rx|d         r|r+|                     |                     ||                    }nC|	r+|                     |                     ||                    }n|
r*|                     |                     ||                    }n|                     |                     ||                    }n|d         r|d         |d<   |r*|                     |                     ||                    }n|	r*|                     |                     ||                    }nU|
r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |d          }t7          |t8                    s|                     |dg           }|                     ||||          S ) Nz1 fetchContractOrders() requires a symbol argumentr   rF  )rh  r   stopr#  stopLossTakeProfitr  Fr'  r(  r  r#  rk  r=   r  r)  r  ri  r   r   r\  rj  r   fetchContractOrdersrl  rm  r   rO   rP   r  re  r]  orders)r*   r=   rF  rc  safe_bool_2rP  r  r  rq  rs  6contractPrivatePostLinearSwapApiV1SwapTriggerHisordersro  3contractPrivatePostLinearSwapApiV1SwapTpslHisorders4contractPrivatePostLinearSwapApiV1SwapTrackHisorders/contractPrivatePostLinearSwapApiV3SwapHisorders;contractPrivatePostLinearSwapApiV1SwapCrossTriggerHisorders8contractPrivatePostLinearSwapApiV1SwapCrossTpslHisorders9contractPrivatePostLinearSwapApiV1SwapCrossTrackHisorders4contractPrivatePostLinearSwapApiV3SwapCrossHisorders0contractPrivatePostSwapApiV1SwapTriggerHisorders-contractPrivatePostSwapApiV1SwapTpslHisorders.contractPrivatePostSwapApiV1SwapTrackHisorders)contractPrivatePostSwapApiV3SwapHisorders0contractPrivatePostApiV1ContractTriggerHisorders-contractPrivatePostApiV1ContractTpslHisorders.contractPrivatePostApiV1ContractTrackHisorders)contractPrivatePostApiV3ContractHisordersr  r  r  )r5  re  r\  r  rR  rc  rp  rU  r#  r(  r  r  r+  s                r7  fetch_contract_orderszhtx.fetch_contract_orders  s   >#DG.a$abbbV$$ 	
 	
 ""669==!__V5IJJ>>&*e<<6#X#X#XYY 
	 ( 
	 H 
	  ',$'-d|GO$%'GM"" (-%"(,GJGFO22:wOO( )	lJ!%!C!CDY[a!b!bJ%/%7jJZ'' r#ZZ[_[f[fgnpv[w[wxxHH' r#WWX\XcXcdkmsXtXtuuHH r#XXY]YdYdelntYuYuvvHH#SSTXT_T_`gioTpTpqqHHw&& w#__`d`k`klsu{`|`|}}HH' w#\\]a]h]hiprx]y]yzzHH w#]]^b^i^ijqsy^z^z{{HH#XXY]YdYdelntYuYuvvHI 	lf~ l l#TTUYU`U`ahjpUqUqrrHH' l#QQRVR]R]^egmRnRnooHH l#RRSWS^S^_fhnSoSoppHH#MMdkkZaciNjNjkkHH! 	l$*:$6! l#TTUYU`U`ahjpUqUqrrHH' l#QQRVR]R]^egmRnRnooHH l#RRSWS^S^_fhnSoSoppHH#MMdkkZaciNjNjkkH^ 622&$'' 	;__VXr::F  >>>r8  c           	      b    ddi}|                      ||||                     ||                    S )Nr   z5,6,7)r=  ro  )r5  re  r\  r  rR  rp  s         r7  fetch_closed_contract_ordersz htx.fetch_closed_contract_orders  s9    g
 ))&%GU[@\@\]]]r8  c                 R   |                                   d}||                     |          }d}|                     d||          \  }}|dk    p|dk    }|r|t          | j        dz   |z   dz             |r|                     ||||          S |                     ||||          S )a  

        https://huobiapi.github.io/docs/spot/v1/en/#search-past-orders
        https://huobiapi.github.io/docs/spot/v1/en/#search-historical-orders-within-48-hours
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-get-history-orders-new
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-get-history-orders-new
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-history-orders-new
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-history-orders-via-multiple-fields-new

        fetches information on multiple orders made by the user
        :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 bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
        :param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.trailing]: *contract only* set to True if you want to fetch trailing stop orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr   rO   rP   z. fetchOrders() requires a symbol argument for  orders)rF  rc  rG  r*   r=   r=  r#  )r5  re  r\  r  rR  rc  rS  r   s           r7  fetch_orderszhtx.fetch_orders  s    * 	[[((F
!??vW]^^
F&(EjH.D 	y#DG.^$^ak$knw$wxxx 	H--feUFKKK))&%GGGr8  c                 p   |                                   d}|                     |dd          \  }}|r|                     d||||d          S d}||                     |          }d}|                     d||          \  }}|dk    r|                     ||||          S |                     ||||          S )aO  

        https://huobiapi.github.io/docs/spot/v1/en/#search-past-orders
        https://huobiapi.github.io/docs/spot/v1/en/#search-historical-orders-within-48-hours
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-get-history-orders-new
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-get-history-orders-new
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-history-orders-new
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-history-orders-via-multiple-fields-new

        fetches information on multiple closed orders made by the user
        :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 int [params.until]: the latest time in ms to fetch entries for
        :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 Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Frq   rd  rC   NrM   )rF  r  rp  rc  rG  r%  r?  )r5  re  r\  r  rR  rd  rc  rS  s           r7  fetch_closed_orderszhtx.fetch_closed_orders  s    & 	88ATV`aa& 	m445H&RWY^`fhklll[[((F
!??@SU[]cdd
F00vNNN44VUE6RRRr8  c                 
   |                                   d}||                     |          }i }d}|                     d||          \  }}d}|                     d||d          \  }}d}	|dk    r||d         |d<   |                     |d          }
|
z|                                  t          dt          | j                            D ]C}| j        |         }|                     |d	          dk    r|                     |d          }
|
 nD|
|d<   |||d
<   | 	                    |d          }| 
                    |                     ||                    }	n||d         |d<   |||d<   |                     |dd          }|                     |d          }|                     |dd          }| 	                    |g d          }|dk    rd}|                     d|          \  }}|dn|}|dk    r|r+|                     |                     ||                    }	n|r+|                     |                     ||                    }	n|r+|                     |                     ||                    }	nm|                     |                     ||                    }	nB|dk    r|r+|                     |                     ||                    }	n|r+|                     |                     ||                    }	n|r+|                     |                     ||                    }	n|                     |                     ||                    }	n|dk    r|dk    r|r+|                     |                     ||                    }	nP|r+|                     |                     ||                    }	n#|r*|                     |                     ||                    }	n|                     |                     ||                    }	n|dk    r|                     |dd          |d<   |r*|                     |                     ||                    }	n|r*|                     |                     ||                    }	nU|r*|                     |                     ||                    }	n)|                     |                     ||                    }	|                     |	d          }tA          |tB                    s|                     |dg           }| "                    ||||          S )a  

        https://huobiapi.github.io/docs/spot/v1/en/#get-all-open-orders
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-current-unfilled-order-acquisition
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-current-unfilled-order-acquisition

        fetch all unfilled currently open orders
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
        :param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :param boolean [params.trailing]: *contract only* set to True if you want to fetch trailing stop orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr   r   rM   r=   re  r  r   r\  re  r  rk  r'  r#  r(  r  Fr)  rl  rm  r   rO   rP   r  usdtr]  r+  )#rF  rc  rG  r  rI  r  rt  ru  r  r  spotPrivateGetV1OrderOpenOrdersro  r,  rP  r  rs  7contractPrivatePostLinearSwapApiV1SwapTriggerOpenorders4contractPrivatePostLinearSwapApiV1SwapTpslOpenorders5contractPrivatePostLinearSwapApiV1SwapTrackOpenorders0contractPrivatePostLinearSwapApiV1SwapOpenorders<contractPrivatePostLinearSwapApiV1SwapCrossTriggerOpenorders9contractPrivatePostLinearSwapApiV1SwapCrossTpslOpenorders:contractPrivatePostLinearSwapApiV1SwapCrossTrackOpenorders5contractPrivatePostLinearSwapApiV1SwapCrossOpenorders1contractPrivatePostSwapApiV1SwapTriggerOpenorders.contractPrivatePostSwapApiV1SwapTpslOpenorders/contractPrivatePostSwapApiV1SwapTrackOpenorders*contractPrivatePostSwapApiV1SwapOpenorders1contractPrivatePostApiV1ContractTriggerOpenorders.contractPrivatePostApiV1ContractTpslOpenorders/contractPrivatePostApiV1ContractTrackOpenorders*contractPrivatePostApiV1ContractOpenordersr  r  r  )r5  re  r\  r  rR  rc  rp  rS  r;  rU  r  ry  r  r#  r(  r  r  r+  s                     r7  fetch_open_orderszhtx.fetch_open_orders  s   " 	[[((F
!??@QSY[abb
F99:KVU[]eff!$*4L!((>>I ""$$$q#dm"4"455 " "A"mA.G''88FBB$($4$4Wd$C$C	$0!E$-GL! "'YYv|44F;;DKKQW<X<XYYHH!+1$<( ',$&&vvyAAG!%9M!N!N~~fj%@@HYYv'\'\'\]]F(""!
%)%G%GHY[a%b%b"
F)3);WW*
++ w#'#_#_`d`k`klsu{`|`|#}#}+ w#'#\#\]a]h]hiprx]y]y#z#z! w#'#]#]^b^i^ijqsy^z^z#{#{#'#X#XY]YdYdelntYuYu#v#v7** |#'#d#deiepepqx  {A  fB  fB  $C  $C+ |#'#a#abfbmbmnuw}b~b~##! |#'#b#bcgcncnovx~cc  $A  $A#'#]#]^b^i^ijqsy^z^z#{#{I%%'' q#'#Y#YZ^ZeZefmouZvZv#w#w+ q#'#V#VW[WbWbcjlrWsWs#t#t! q#'#W#WX\XcXcdkmsXtXt#u#u#'#R#RSWS^S^_fhnSoSo#p#p8++(,(8(8V(T(TGH% q#'#Y#YZ^ZeZefmouZvZv#w#w+ q#'#V#VW[WbWbcjlrWsWs#t#t! q#'#W#WX\XcXcdkmsXtXt#u#u#'#R#RSWS^S^_fhnSoSo#p#pr 622&$'' 	;__VXr::F  >>>r8  r   c                 R    ddddddddddddddd}|                      |||          S )Nr  canceledclosed	canceling)zpartial-filledzpartial-canceledfilledrZ  	submittedr  r  23456711rI  r5  r   statusess      r7  parse_order_statuszhtx.parse_order_status%  sT     % *"!
 
$ &&999r8  rJ  c           	         |                      |dd          }|                     |                      |dd                    }|d}|                     |g d          }|                     |d          }|                     |d          }d	|v r+|d	                             d
          }|d         }|d         }|                      |dd          }	|                     |	|          }|                     |g d          }
|                      |dd          }d }d }|0|                    d          dk    r|                     |d          }n/|                      |dd          }|                     |g d          }|                     |g d          }|                      |dd          }|                      |dd          }|                     |d|          }d }|Kd }|                     |d          }||                     |          }n|dk    r|d         n|d          }||d!}|                     |d"          }| 	                    |d#          }| 
                    |d$          }d }|
|dk    rd%nd&}|                     i d'|d(|d)|d*|
d+|                     |
          d,d d|d         d	|d-d d.d d/|d|d0|                      |d1d2          d3|d4|d|d5|d ||||d6|          S )7Nerr_codeerr-coder  r   rejected)r=   order_id_strr<  r'  order_price_typer\  r  r   r   r  re  )r;  r:  r  r  client-order-idrc  field-cash-amountvolumer  )zfilled-cash-amountrq  rB  )r@  zfield-amountrA  r  order_pricerC  z
field-feesrb  rE  sellr  r  rG  trade_avg_pricero  reduce_onlyFTrE  r=   r  r  rY  lastTradeTimestampr  postOnlyr(  r  
stop-pricetrigger_pricer  r  r]  )	remainingr   
reduceOnlyrb  ro  )r  ri  rO  rI  r  r)  safe_integer_nrN  r  rP  r  
safe_orderr  )r5  rJ  rc  rejectedCreateOrdersr   r=   r(  r\  	orderTyperj  r  r  r  r  r]  r  rU  rb  rW  rV  r  ro  reduceOnlyIntegerr|  s                           r7  r  zhtx.parse_order:  s   N  $11%ZPP((););E7H)U)UVV+F'I'I'IJJ{33'9::U??f++C00IQ<DQ<D%%e_hGG!!(F33''/Z/Z/Z[[	**52CE[\\499X#6#6!#;#;##E+>??DD''xBBF%%e-j-j-jkkD##E+\+\+\]]""5'=AA$$UM<HH""5%99K ,,UK@@M("55mDD26&..fWoovf~' C ""5*;<<11 --e]CC
(#4#9#9J  
E 
" 
 ] 
 	 

 Y// 
 !$ 
 fX& 
 D 
 4 
  
 D 
 U 
 D..ulOTT 
 w 
 D 
  f! 
" f# 
$ $- 
  
  
. /  	r8  r  c                     |                                   |                     |          }|d         st          | j        dz             d|d<   |                     |dd|d|          S )a  
        create a market buy order by providing the symbol and cost

        https://www.htx.com/en-us/opend/newApiPages/?id=7ec4ee16-7773-11ed-9966-0242ac110003

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        rM   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  rc  buyN)rF  rc  r0   r=   create_order)r5  re  r  rR  rc  s        r7  !create_market_buy_order_with_costz%htx.create_market_buy_order_with_cost  ss     	V$$f~ 	ftw)ddeee6;23  5$fMMMr8  r(  r  r  trailingPercenttrailingTriggerPricec	                     |t          | j        dz             |t          | j        dz             ||d<   ||d<   |                     ||||||          S )a  
        create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
        :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 you want to trade in units of the base currency, or number of contracts
        :param float [price]: the price for the order to be filled at, in units of the quote currency, ignored in market orders
        :param float trailingPercent: the percent to trail away from the current market price
        :param float trailingTriggerPrice: the price to activate a trailing order, default uses the price argument
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NzA createTrailingPercentOrder() requires a trailingPercent argumentzF createTrailingPercentOrder() requires a trailingTriggerPrice argumentr  r  )r*   r=   r  )	r5  re  r\  r(  r  r  r  r  rR  s	            r7  create_trailing_percent_orderz!htx.create_trailing_percent_order  sp     "#DG.q$qrrr'#DG.v$vwww$3 !)=%&  tVUFKKKr8  c                    |                                   |                                  |                     |          }d}|                     d|          \  }}|                     |d         ||          }	|	|d         d}
|                    dd          }|                    dd          }|                     | j        |d         i           }|                     |g d	          }|3|                     |d
i           }||v rt          | j
        dz             nz|dk    rdnd}|                     |d|          }|                     ||          |
d<   ||
d<   |dk    s|dk    rd|z   }n)|dk    r#|dk    rt          | j
        dz   |z   dz             d}|                     |dk    |dk    |          \  }}|rd}|                     |dd          }|dk    r|dz   }n|dk    rd}|d z   |z   |
d<   |                     |d!d"          }|M|                     | j        d#i           }|                     |d          }||                                 z   |
d"<   n||
d"<   |d$k    rd%|
d&<   n|d'k    rd(|
d&<   n|d)k    rd*|
d&<   |dk    r|d+k    rd}d,}|                     |dd-d,          \  }}|                     |d.          }|                     |d.          }||                     ||          }n|rm|t+          | j
        d/z             |                     |          }|                     |          }|                     |t/          j        ||                    }n|                     ||          }||
d0<   n|                     ||          |
d0<   |                     |d1i           }||v r|                     ||          |
d2<   |                     |g d3          }|                     |
|          S )4a  
 @ignore
        helper function to build request
        :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 you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.timeInForce]: supports 'IOC' and 'FOK'
        :param float [params.cost]: the quote quantity that can be used alternative for the amount for market buy orders
        :returns dict: request to be sent to the exchange
        Nr_   r\  r=   )r  re  zbuy- zsell-)r  	stopPricery  r  z: createOrder() requires a triggerPrice for a trigger orderrt  ltegteoperatorry  r  r  zstop-r  r  z  createOrder() does not support rA  rc  r  r  r  r
  z-fokr	  r  r  r  rp  r  rl  zsuper-margin-apisourcerm  z
margin-apic2czc2c-margin-apir  Tr  r  z createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argumentr  r  r  )r  r  ry  r  rp  r  r  )rF  r  rc  rs  r  replacerP  r  rO  r*   r=   rI  price_to_precisionr0   handle_post_onlyr  uuidr  ri  r  amount_to_precisionr.   number_to_stringr8   
string_mulro  )r5  re  r\  r(  r  r  rR  rc  r  r  rp  r  r  r  r  defaultOperatorstopOperatorrx  r  r  r  brokerIdquoteAmountr  r  rS  rR  r  s                               r7  create_spot_order_requestzhtx.create_spot_order_request  s    	V$$
!??vVV
F11&.*fUU	 $Tl
 
 LL,,	%%gr22	//$,vCC))&2]2]2]^^!__W6FKKNN**'2n(nooo + )-eeUO++FJPPL$($;$;FL$Q$QGL!".GJW$$){*B*B#i/		|++)?O2O2O"47-O#ORV#VYb#bccc00h1F	UbHbdjkk& 	&%I&&v}eDD%!F*IIE!!I*y0**6?DUVV __T\8R@@F''55H)1DIIKK)?G%&&)6G%&   2GH:%% ,GH5   0GH!!K04-8<8U8UV\^k  nQ  SW  9X  9X5-v##FF33DYYvv..F"66vtDD2 G=&tw  2m  (m  n  n  n $(#8#8#@#@L"&"7"7">">K"&":":67CUVbdoCpCp"q"qKK"66vvFF +GH $ 8 8 H HGH//'3DbII''#66vuEEGG6  $N  $N  $N  O  O{{7F+++r8  c                    |                      |          }|d         |                     ||          |d}d}	|                     |dk    |dk    |          \  }	}|	rd}|                     |dd          }
|
dk    rd	}n|
d
k    rd}|                     |g d          }|                     |dd          }|                     |dd          }|                     |dd          }|                     |d|          }|du}|du}|du}|du}|rS|                     |ddd          }||d<   |                     ||          |d<   ||                     ||          |d<   n1|s|rv|r:||d<   |                     ||          |d<   ||                     ||          |d<   n||d<   |                     ||          |d<   ||                     ||          |d<   n|rMt          j
        |d          }|                     |          |d<   ||d<   |                     |dd           |d<   nh|                     |d!d"          }|||d!<   |                     |d"g          }|d#k    s|dk    s|d	k    s|dk    r||                     ||          |d$<   |                     |d%d&d'          }|s,|s*|rd(|d&<   |                     |g d)d(          |d*<   |s||d<   |                     |d+d'          }|r|rd,|d-<   nd.|d-<   |                     | j        d/i           }|                     |d          }||d0<   |                     |g d1          }|                     ||          S )2a  
 @ignore
        helper function to build request
        :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 you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.timeInForce]: supports 'IOC' and 'FOK'
        :param float [params.trailingPercent]: *contract only* the percent to trail away from the current market price
        :param float [params.trailingTriggerPrice]: *contract only* the price to trigger a trailing order, default uses the price argument
        :returns dict: request to be sent to the exchange
        r=   )r  rr  r'  Nrc  	post_onlyr  r  r
  fokr	  r  r  r  rz  r  sl_trigger_pricer  tp_trigger_pricer  callback_rater  triggerTypetrigger_typelerz  rs  sl_order_price_typesl_order_pricetp_order_price_typetp_order_price100active_pricero  formula_pricer  r  r  r  r|  rv  Fr   )	leverRate
lever_rater  r  r  r  offsetr  r  channel_code)r|  r  r  r  r  r  r  r  r  r  r  r  )rc  r  r  rI  safe_number_nsafe_number_2r  ri  r  r8   
string_divparse_to_numericr`  r  r,  r}  r  rP  r  ro  )r5  re  r\  r(  r  r  rR  rc  rp  rx  r  r  stopLossTriggerPricetakeProfitTriggerPricer  r  isTrailingPercentOrder	isTriggerisStopLossTriggerOrderisTakeProfitTriggerOrderr  trailingPercentStringr  r|  r  r  r  s                              r7  create_contract_order_requestz!htx.create_contract_order_requestu  sy    V$$#D\..vv>>
 

 001A4;CVX^__& 	D&&v}eDD%DDE!!D))&2`2`2`aa#11&/K]^^!%!3!3F<MOa!b!b,,V5FXX#//8NPUVV!0!< ,	!5T!A#9#E  	N,,V]NTXYYK&1GN#'+'>'>v|'T'TGO$ )-)@)@)O)O&# 	N'? 	N% 	W15-..2.E.EfNb.c.c*+$040G0GPU0V0VG,-15-..2.E.EfNd.e.e*+$040G0GPU0V0VG,-# 	N$+$6$N$N!'+'<'<=R'S'SGO$&:GN#*.*:*:6CUWf*g*gG&'' //8I?[[M(-:)*6O+<==w$%--45==DKDWDW$'+'>'>vu'M'MGG$%%flM5QQ
% 	3.F 	3 +)*&$($7$7@g@g@gij$k$kGL!) 3.2*+%88 	+ +$+!!$*!x<<##FD11"*6  $_  $_  $_  `  `{{7F+++r8  c                    |                                   |                     |          }|                     |g d          }|                     |dd          }	|                     |dd          }
|                     |d          }|du}|du}|	du}|
du}d}|d         rJ|rt          | j        d	z             |                     ||||||          }|                     |          }n| 	                    ||||||          }|d
         rd}| 
                    d|          \  }}|dn|}|dk    rd|r|                     |          }n|s|r|                     |          }n|r|                     |          }n|                     |          }np|dk    rb|r|                     |          }nQ|s|r|                     |          }n6|r|                     |          }n|                     |          }n|d         r|                     |d          }|t)          | j        dz             |d         r`|r|                     |          }n|s|r|                     |          }n|r|                     |          }n}|                     |          }ng|d         r_|r|                     |          }nG|s|r|                     |          }n-|r|                     |          }n|                     |          }d}d}|d         ra|                     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i|          S |r/|                     |di           }|                     |d&i           }nH|r/|                     |di           }|                     |d'i           }n|                     |di           }|                     ||          S )(a  
        create a trade order

        https://huobiapi.github.io/docs/spot/v1/en/#place-a-new-order                   # spot, margin
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-an-order        # coin-m swap
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-trigger-order   # coin-m swap trigger
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-an-order           # usdt-m swap cross
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-trigger-order      # usdt-m swap cross trigger
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-an-order        # usdt-m swap isolated
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-trigger-order   # usdt-m swap isolated trigger
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-set-a-take-profit-and-stop-loss-order-for-an-existing-position
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-set-a-take-profit-and-stop-loss-order-for-an-existing-position
        https://huobiapi.github.io/docs/dm/v1/en/#place-an-order                        # coin-m futures
        https://huobiapi.github.io/docs/dm/v1/en/#place-trigger-order                   # coin-m futures contract trigger

        :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 you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: the price a trigger order is triggered at
        :param str [params.triggerType]: *contract trigger orders only* ge: greater than or equal to, le: less than or equal to
        :param float [params.stopLossPrice]: *contract only* the price a stop-loss order is triggered at
        :param float [params.takeProfitPrice]: *contract only* the price a take-profit order is triggered at
        :param str [params.operator]: *spot and margin only* gte or lte, trigger price condition
        :param str [params.offset]: *contract only* 'both'(linear only), 'open', or 'close', required in hedge mode and for inverse markets
        :param bool [params.postOnly]: *contract only* True or False
        :param int [params.leverRate]: *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
        :param str [params.timeInForce]: supports 'IOC' and 'FOK'
        :param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
        :param float [params.trailingPercent]: *contract only* the percent to trail away from the current market price
        :param float [params.trailingTriggerPrice]: *contract only* the price to trigger a trailing order, default uses the price argument
        :param bool [params.hedged]: *contract only* True for hedged mode, False for one way mode, default is False
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r  r  r  r  r  r  NrM   z@ createOrder() does not support trailing orders for spot marketsr   r_   rl  rm  r   r  z createOrder() requires an extra parameter params["offset"] to be set to "open" or "close" when placing orders in inverse marketsrO   rP   rE  r=   r]  r  rY  rw  r   re  r\  r(  r  r  r]  r{  r  ro  rb  r  r  sl_ordertp_order) rF  rc  r  r  ri  r0   r=   r  !spotPrivatePostV1OrderOrdersPlacer  rs  2contractPrivatePostLinearSwapApiV1SwapTriggerOrder/contractPrivatePostLinearSwapApiV1SwapTpslOrder0contractPrivatePostLinearSwapApiV1SwapTrackOrder+contractPrivatePostLinearSwapApiV1SwapOrder7contractPrivatePostLinearSwapApiV1SwapCrossTriggerOrder4contractPrivatePostLinearSwapApiV1SwapCrossTpslOrder5contractPrivatePostLinearSwapApiV1SwapCrossTrackOrder0contractPrivatePostLinearSwapApiV1SwapCrossOrderrI  r*   ,contractPrivatePostSwapApiV1SwapTriggerOrder)contractPrivatePostSwapApiV1SwapTpslOrder*contractPrivatePostSwapApiV1SwapTrackOrder%contractPrivatePostSwapApiV1SwapOrder,contractPrivatePostApiV1ContractTriggerOrder)contractPrivatePostApiV1ContractTpslOrder*contractPrivatePostApiV1ContractTrackOrder%contractPrivatePostApiV1ContractOrderr~  rP  r  )r5  re  r\  r(  r  r  rR  rc  r  r  r  r  r  r  r  r  rU  spotRequestcontractRequestr  r  r]  rx  s                          r7  r  zhtx.create_order  s   J 	V$$))&2`2`2`aa#11&/K]^^!%!3!3F<MOa!b!b**63DEE!0!< ,	!5T!A#9#E &> 2	_% q"47-o#oppp88tVUZ\bccK==kJJHH"@@tU[]bdjkkOh +_!
.2.P.PQ^`o.p.p+
O)3);WW*
++  e#'#Z#Z[j#k#k/ e3K e#'#W#WXg#h#h/ e#'#X#XYh#i#i#'#S#STc#d#d7**  j#'#_#_`o#p#p/ j3K j#'#\#\]l#m#m/ j#'#]#]^m#n#n#'#X#XYh#i#i	" _))&(;;>+DG  7z  -z  {  {  {&> _  _#'#T#TUd#e#e/ _3K _#'#Q#QRa#b#b/ _#'#R#RSb#c#c#'#M#Mo#^#^H% _  _#'#T#TUd#e#e/ _3K _#'#Q#QRa#b#b/ _#'#R#RSb#c#c#'#M#Mo#^#^> &> 	;?? $$d&&x88$ T$ D	$
 %d$ $$ $$ $ $ $ &$ $$ T$ $ $$  t!$"  #$$ 4%$ $& '  ( $ 	;??8VR88D__T:r::FF% 	;??8VR88D__T:r::FF__Xvr::F///r8  r+  c           	         |                                   g }d}d}d}t          dt          |                    D ]s}||         }|                     |d          }	||	}n||	k    rt	          | j        dz             |                     |d          }
|                     |d          }|                     |d          }|                     |d          }|                     |d	i           }|                     d
|          }|d         }|"||}n||k    rt	          | j        dz             |                     |          }d}|d         r| 	                    |	|
||||          }n| 
                    |	|
||||          }|                     |d          }|                    |           ui }d}|d         r|                     |          }n||d<   |d         r>|dn|}|dk    r|                     |          }n_|dk    r|                     |          }nC|d         r;|d         r|                     |          }n|d         r|                     |          }d}|d         r|                     |dg           }n[|                     |di           }|                     |dg           }|                     |dg           }|                     ||          }|                     ||          S )a-  
        create a list of trade orders

        https://huobiapi.github.io/docs/spot/v1/en/#place-a-batch-of-orders
        https://huobiapi.github.io/docs/dm/v1/en/#place-a-batch-of-orders
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-a-batch-of-orders
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-a-batch-of-orders
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-a-batch-of-orders

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   re  z; createOrders() requires all orders to have the same symbolr\  r(  r  r  rR  r`   zS createOrders() requires all orders to have the same margin mode(isolated or cross)rM   r  orders_datar   rl  rm  r   rO   rP   r]  successerrors)rF  rt  ru  rI  r+   r=   rP  rs  rc  r  r  r  r  privatePostOrderBatchOrders0contractPrivatePostLinearSwapApiV1SwapBatchorder5contractPrivatePostLinearSwapApiV1SwapCrossBatchorder*contractPrivatePostSwapApiV1SwapBatchorder*contractPrivatePostApiV1ContractBatchorderr  r  )r5  r+  rR  ordersRequestsre  rc  r  ry  rawOrderrj  r\  r(  r  r  orderParamsmarginResultcurrentMarginModeorderRequestrp  rU  rx  r]  r  r  s                           r7  create_orderszhtx.create_orderso  se    	
q#f++&& 	0 	0AayH''(;;H~!X%%$TW/l%lmmm##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAK==nkZZL ,Q ,%!2JJ!%666(  4I  *I  J  J  J[[((FLf~ t#==hdTZ\acnoo#AA(DRVX^`egrss99\<@@L!!,////&> 	X77GGHH%3GM"h 
X)3);WW*
++#TTU\]]HH7**#YYZabbH	" X&> X#NNwWWHHH% X#NNwWWHT &> 	8__Xvr::FF??8VR88DoodIr::G__T8R88F&&w77F  000r8  c                  
   |                                   d}||                     |          }d}|                     d||          \  }}i }d}|dk    r|                     |dd          }|0||d<   |                     |                     ||                    }nF||d<   |                     |ddg          }|                     |                     ||                    }n|t          | j	        dz             |                     |dd          }|||d	<   n||d<   |                     |ddg          }|d
         r|d         |d<   n|d         |d<   | 
                    |dd          }	|                     |d          }
|                     |dd          }|                     |g d          }|d         rd}|                     d|          \  }}|dn|}|dk    r|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }n|r+|                     |                     ||                    }nw|                     |                     ||                    }nL|dk    r|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }n|r+|                     |                     ||                    }n|                     |                     ||                    }n|d         rn|d         r|	r+|                     |                     ||                    }nV|
r+|                     |                     ||                    }n)|r*|                     |                     ||                    }n|                     |                     ||                    }n|d
         r|	r*|                     |                     ||                    }n|
r*|                     |                     ||                    }ns|r*|                     |                     ||                    }nG|                     |                     ||                    }nt=          | j	        dz   |z   dz             |                     |                     ||          |dd          S )a  
        cancels an open 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 boolean [params.trigger]: *contract only* if the order is a trigger trigger order or not
        :param boolean [params.stopLossTakeProfit]: *contract only* if the order is a stop-loss or take-profit order
        :param boolean [params.trailing]: *contract only* set to True if you want to cancel a trailing order
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        NrW   rM   rp  r  r<  z) cancelOrder() requires a symbol argumentr  r=  rP   r  re  r=   r  r'  r#  r(  r  Fr)  r   rl  rm  r   rO   z  cancelOrder() does not support rn  rZ  )r=   r   ) rF  rc  rG  r  /spotPrivatePostV1OrderOrdersOrderIdSubmitcancelro  r  3spotPrivatePostV1OrderOrdersSubmitCancelClientOrderr*   r=   r,  rP  r  rs  3contractPrivatePostLinearSwapApiV1SwapTriggerCancel0contractPrivatePostLinearSwapApiV1SwapTpslCancel1contractPrivatePostLinearSwapApiV1SwapTrackCancel,contractPrivatePostLinearSwapApiV1SwapCancel8contractPrivatePostLinearSwapApiV1SwapCrossTriggerCancel5contractPrivatePostLinearSwapApiV1SwapCrossTpslCancel6contractPrivatePostLinearSwapApiV1SwapCrossTrackCancel1contractPrivatePostLinearSwapApiV1SwapCrossCancel-contractPrivatePostSwapApiV1SwapTriggerCancel*contractPrivatePostSwapApiV1SwapTpslCancel+contractPrivatePostSwapApiV1SwapTrackCancel&contractPrivatePostSwapApiV1SwapCancel-contractPrivatePostApiV1ContractTriggerCancel*contractPrivatePostApiV1ContractTpslCancel+contractPrivatePostApiV1ContractTrackCancel&contractPrivatePostApiV1ContractCancelr0   r  )r5  r=   re  rR  rc  rS  rp  rU  r  r#  r(  r  r  s                r7  cancel_orderzhtx.cancel_order  s    	[[((F
!??vW]^^
F
  ..v7H/ZZM$&(
#OOPTP[P[\cekPlPlmm-:)*6,=+OPPSSTXT_T_`gioTpTpqq~'2](]^^^ ..v7H/ZZM$&(
##-:)*6,=+OPPh 8$*:$6!!+1$<(&&vvyAAG!%9M!N!N~~fj%@@HYYv'\'\'\]]Fh *k!
%)%G%GW]%^%^"
F)3);WW*
++ s#'#[#[\`\g\ghoqw\x\x#y#y+ s#'#X#XY]YdYdelntYuYu#v#v! s#'#Y#YZ^ZeZefmouZvZv#w#w#'#T#TUYU`U`ahjpUqUq#r#r7** x#'#`#`aealalmtv|a}a}#~#~+ x#'#]#]^b^i^ijqsy^z^z#{#{! x#'#^#^_c_j_jkrtz_{_{#|#|#'#Y#YZ^ZeZefmouZvZv#w#w	" k&> m m#'#U#UVZVaVabikqVrVr#s#s+ m#'#R#RSWS^S^_fhnSoSo#p#p! m#'#S#STXT_T_`gioTpTp#q#q#'#N#Nt{{[bdjOkOk#l#lH% m m#'#U#UVZVaVabikqVrVr#s#s+ m#'#R#RSWS^S^_fhnSoSo#p#p! m#'#S#STXT_T_`gioTpTp#q#q#'#N#Nt{{[bdjOkOk#l#l"47-O#OR\#\_i#ijjj( {{4++Hf== @
 @
   	r8  idsc                 (	   |                                   d}||                     |          }d}|                     d||          \  }}i }d}|dk    r|                     |dd          }|                     |dd|          }|"t	          |t
                    r|g|d<   n?||d<   n9t	          |t
                    r|g|d<   n||d<   |                     |g d	          }|                     |                     ||                    }n^|t          | j
        d
z             |                     |dd          }|                     |dd|          }|d                    |          |d<   n||d<   |                     |g d          }|d         r|d         |d<   n|d         |d<   |                     |dd          }	|                     |d          }
|                     |g d          }|d         r7d}|                     d|          \  }}|dn|}|dk    r|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }n|                     |                     ||                    }n|dk    r|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }ne|                     |                     ||                    }n:|d         r|d         r|	r*|                     |                     ||                    }n|
r*|                     |                     ||                    }n|                     |                     ||                    }n|d         r|	r*|                     |                     ||                    }ns|
r*|                     |                     ||                    }nG|                     |                     ||                    }nt9          | j
        dz   |z   dz             |                     |d           }|                     |          S )!a  
        cancel multiple orders
        :param str[] ids: order ids
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
        :param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :returns dict: an list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        NrX   rM   rp  r  client-order-idsclientOrderIdsz	order-ids)rp  r  r  r  z* cancelOrders() requires a symbol argumentr  client_order_ids,r=  )r  r  r  r  rP   r  re  r=   r  r'  r#  r(  )r'  r(  r#  r   rl  rm  r   rO   z! cancelOrders() does not support rn  r]  )rF  rc  rG  r  r  strr  'spotPrivatePostV1OrderOrdersBatchcancelro  r*   r=   r  joinr,  rP  rs  r  r  r  r  r  r  r  r  r  r  r  r  r0   r  parse_cancel_orders)r5  r  re  rR  rc  rS  rp  rU  r  r#  r(  r  r]  s                r7  cancel_orderszhtx.cancel_orders^  s/    	[[((F
!??PVX^__
F	
 !..v7H/ZZN!..v7IK[]kllN%nc22 /,/5GK((+.GK((nc22 A3A2BG.//2@G./6+u+u+uvvCCDKKPWY_D`D`aaHH~'2^(^___!//8I?[[N!//8JL\^lmmN%&)hhsmm
##-;)*6+u+u+uvvh 8$*:$6!!+1$<(&&vvyAAG!%9M!N!NYYv'P'P'PQQFh "l!
%)%G%GX^%_%_"
F)3);WW*
++ s#'#[#[\`\g\ghoqw\x\x#y#y+ s#'#X#XY]YdYdelntYuYu#v#v#'#T#TUYU`U`ahjpUqUq#r#r7** x#'#`#`aealalmtv|a}a}#~#~+ x#'#]#]^b^i^ijqsy^z^z#{#{#'#Y#YZ^ZeZefmouZvZv#w#w	" l&> m m#'#U#UVZVaVabikqVrVr#s#s+ m#'#R#RSWS^S^_fhnSoSo#p#p#'#N#Nt{{[bdjOkOk#l#lH% m m#'#U#UVZVaVabikqVrVr#s#s+ m#'#R#RSWS^S^_fhnSoSo#p#p#'#N#Nt{{[bdjOkOk#l#l"47-P#PS]#]`j#jkkkh ~~h//''---r8  c                 l   |                      |d          }d }||                    d          }n|                     |dg           }|                     |ddg           }g }t	          dt          |                    D ]6}||         }|                    |                     ||dd                     7t	          dt          |                    D ]`}||         }|                    |                     ||                     |d	d
          d|                      |d          d                     a|S )N	successesr  r  r  failedr   rZ  )rE  r=   r   r<  r=  rp  )rE  r=   r   r  )	rI  r  r  r  rt  ru  r  r~  r  )r5  r+  r  r  r  rx  ry  rJ  s           r7  r  zhtx.parse_cancel_orders  se   : $$V[99	 ooc**GGnnVY;;G!!&(HbAAq#g,,'' 	 	AAJEMM$//$+ +      
 q#f++&& 	 	A1IEMM$//((
JGG"!%!1!1%9J!K!K	+ +       r8  c                 H	   |                                   d}||                     |          }d}|                     d||          \  }}i }d}|dk    rd||d         |d<   |                     |                     ||                    }|                     |d          }|                     d|i          gS |t          | j        dz             |d	         r|d
         |d<   |d         |d<   | 	                    |dd          }| 
                    |d          }	|                     |dd          }
|                     |g d          }|d         rd}|                     d|          \  }}|dn|}|dk    r|r+|                     |                     ||                    }n|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }nw|                     |                     ||                    }nL|dk    r|r+|                     |                     ||                    }n|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }n|                     |                     ||                    }n|d         rn|d         r|r+|                     |                     ||                    }nV|	r+|                     |                     ||                    }n)|
r*|                     |                     ||                    }n|                     |                     ||                    }n|d	         r|r*|                     |                     ||                    }n|	r*|                     |                     ||                    }ns|
r*|                     |                     ||                    }nG|                     |                     ||                    }nt=          | j        dz   |z   dz             |                     |d          }|                     |          S )a  
        cancel all open 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 boolean [params.trigger]: *contract only* if the orders are trigger trigger orders or not
        :param boolean [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :param boolean [params.trailing]: *contract only* set to True if you want to cancel all trailing orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        NrU   rM   r=   re  r]  rE  z- cancelAllOrders() requires a symbol argumentrP   r  r  r'  r#  r(  r  Fr)  r   rl  rm  r   rO   z$ cancelAllOrders() does not support rn  ) rF  rc  rG  1spotPrivatePostV1OrderOrdersBatchCancelOpenOrdersro  r  r~  r*   r=   r,  rP  r  r  rs  6contractPrivatePostLinearSwapApiV1SwapTriggerCancelall3contractPrivatePostLinearSwapApiV1SwapTpslCancelall4contractPrivatePostLinearSwapApiV1SwapTrackCancelall/contractPrivatePostLinearSwapApiV1SwapCancelall;contractPrivatePostLinearSwapApiV1SwapCrossTriggerCancelall8contractPrivatePostLinearSwapApiV1SwapCrossTpslCancelall9contractPrivatePostLinearSwapApiV1SwapCrossTrackCancelall4contractPrivatePostLinearSwapApiV1SwapCrossCancelall0contractPrivatePostSwapApiV1SwapTriggerCancelall-contractPrivatePostSwapApiV1SwapTpslCancelall.contractPrivatePostSwapApiV1SwapTrackCancelall)contractPrivatePostSwapApiV1SwapCancelall0contractPrivatePostApiV1ContractTriggerCancelall-contractPrivatePostApiV1ContractTpslCancelall.contractPrivatePostApiV1ContractTrackCancelall)contractPrivatePostApiV1ContractCancelallr0   r  )r5  re  rR  rc  rS  rp  rU  r]  r#  r(  r  r  s               r7  cancel_all_orderszhtx.cancel_all_orders(  sA    	[[((F
!??@QSY[abb
F
 !$*4L!MMdkkZaciNjNjkkH >>(F33DD!    ~'2a(abbbh 7$*:$6!'-d|GO$&&vvyAAG!%9M!N!N~~fj%@@HYYv'\'\'\]]Fh *o!
%)%G%GHY[a%b%b"
F)3);WW*
++ v#'#^#^_c_j_jkrtz_{_{#|#|+ v#'#[#[\`\g\ghoqw\x\x#y#y! v#'#\#\]a]h]hiprx]y]y#z#z#'#W#WX\XcXcdkmsXtXt#u#u7** {#'#c#cdhdodopwy  eA  eA  $B  $B+ {#'#`#`aealalmtv|a}a}#~#~! {#'#a#abfbmbmnuw}b~b~###'#\#\]a]h]hiprx]y]y#z#z	" o&> p p#'#X#XY]YdYdelntYuYu#v#v+ p#'#U#UVZVaVabikqVrVr#s#s! p#'#V#VW[WbWbcjlrWsWs#t#t#'#Q#QRVR]R]^egmRnRn#o#oH% p p#'#X#XY]YdYdelntYuYu#v#v+ p#'#U#UVZVaVabikqVrVr#s#s! p#'#V#VW[WbWbcjlrWsWs#t#t#'#Q#QRVR]R]^egmRnRn#o#o"47-S#SV`#`cm#mnnn >>(F33D++D111r8  r  c                     |                                   d|dk    r|                     |dz            ndi}|                     |                     ||                    }|S )ad  
        dead man's switch, cancel all orders after the given timeout

        https://huobiapi.github.io/docs/spot/v1/en/#dead-man-s-switch

        :param number timeout: time in milliseconds, 0 represents cancel the timer
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: the api result
        r  r   r&  )rF  r  %v2PrivatePostAlgoOrdersCancelAllAfterro  )r5  r  rR  rp  rU  s        r7  cancel_all_orders_afterzhtx.cancel_all_orders_after  sl     	Wq[[t((4888q
 ==dkk'SY>Z>Z[[ r8  rH  c                    |                      |d          }|                      |d          }|                      |d          }|                     ||          }|                     ||          }|                      |d          }|                      |d          }|                     |           ||||                     |          ||dS )Naddress
addressTagrH  noter  )rH  r  tagr  r   rE  )rI  r  r  check_addressr  )	r5  depositAddressrH  r  r!  r  r  r   r  s	            r7  parse_deposit_addresszhtx.parse_deposit_address  s     "">9==~|<<%%njAA
%%j(;;&&z8<<77$$^W==	7###..y99"
 
 	
r8  r  c                 P   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     ||d         gd          }|                     |d          S )a  

        https://www.htx.com/en-us/opend/newApiPages/?id=7ec50029-7773-11ed-9966-0242ac110003

        fetch a dictionary of addresses for a currency, indexed by network
        :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: a dictionary of `address structures <https://docs.ccxt.com/?id=address-structure>` indexed by the network
        rH  r=   r]  r  Fr  )rF  rH  %spotPrivateGetV2AccountDepositAddressro  rP  parse_deposit_addressesindex_by)r5  r  rR  rH  rp  rU  r]  parseds           r7  "fetch_deposit_addresses_by_networkz&htx.fetch_deposit_addresses_by_network  s     	==&&
 ==dkk'SY>Z>Z[[ x44--dXf5E4FNN}}VY///r8  c                     |                                   |                     |          }|                     |          \  }}|                     ||          }|                     |d         ||          }||         S )a  
        fetch the deposit address for a currency associated with self account

        https://www.htx.com/en-us/opend/newApiPages/?id=7ec50029-7773-11ed-9966-0242ac110003

        :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  )rF  rH  handle_network_code_and_paramsr*  )select_network_code_from_unified_networks)r5  r  rR  rH  r  paramsOmitedindexedAddressesselectedNetworkCodes           r7  fetch_deposit_addresszhtx.fetch_deposit_address  s     	==&&$($G$G$O$O!\BB4VV"LLXV\M]_jl|}} 344r8  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     ||d         gd          }	g }
t          dt          |	                    D ]C}|	|         }|d u p|d         |k    }|d u p|d         |k    }|r|r|
                    |           D|
S )	NrH  r=   r]  r  Fr   r   r  )	rF  rH  &spotPrivateGetV2AccountWithdrawAddressro  rP  r'  rt  ru  r  )r5  r  r   r  rR  rH  rp  rU  r]  allAddresses	addressesry  r  	noteMatchnetworkMatchs                  r7  fetch_withdraw_addresseszhtx.fetch_withdraw_addresses  s   ==&&
 >>t{{7TZ?[?[\\ x4433D8F;K:LeTT	q#l++,, 	* 	*A"1oGC76?d+BI'4/WWY5G;5VL *\ *  )))r8  c                 2   ||dk    rd}|                                   d}||                     |          }dddd}||d         |d<   |||d	<   |                     |                     ||                    }|                     |d
         |||          S )a$  

        https://www.htx.com/en-us/opend/newApiPages/?id=7ec4f050-7773-11ed-9966-0242ac110003

        fetch all deposits made to an account
        :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>`
        NrC   r  nextr   r\  directr  r=   rH  re  r]  rF  rH  $spotPrivateGetV1QueryDepositWithdrawro  parse_transactionsr5  r  r\  r  rR  rH  rp  rU  s           r7  fetch_depositszhtx.fetch_deposits$  s     =ECKKE}}T**H
 

 "*4.GJ#GFO<<T[[RX=Y=YZZ6 &&x'75%PPPr8  c                 2   ||dk    rd}|                                   d}||                     |          }dddd}||d         |d<   |||d	<   |                     |                     ||                    }|                     |d
         |||          S )a0  
        fetch all withdrawals made from an account

        https://huobiapi.github.io/docs/spot/v1/en/#search-for-existed-withdraws-and-deposits

        :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>`
        NrC   r   r:  r   r;  r=   rH  re  r]  r=  r@  s           r7  fetch_withdrawalszhtx.fetch_withdrawals\  s     =ECKKE}}T**H
 

 "*4.GJ#GFO<<T[[RX=Y=YZZ2 &&x'75%PPPr8  transactionc                    |                      |d          }|                     |                     |d                    }|                     |d          }|dk    rd}|                     |d          }|t          j        |          }|                     |d          }|                     |d          }|d	k    r|                    d
          dk     rd
|z   }|                     |d          }	|	dk    }
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"S )#Nr:  rH  r\  r   
withdrawalrb  r  ztx-hashr%  0xr   zsub-typeFASTrE  r=   r]  txidr  rY  r  r  	addressToaddressFromr!  zaddress-tagtagTotagFromr  r   r  rC  z
updated-at)rH  r  rate)commentinternalrb  )r  r  rI  r8   
string_absrN  r  r  r  ri  parse_transaction_statusr4  )r5  rD  rH  r  r  r\  rU  r  txHashr;  rP  s              r7  parse_transactionzhtx.parse_transaction  s   f %%k<@@	&&t'7'7Z'P'PQQV44:D"";66(11G$$['::	!!+y99&++d"3"3a"7"7F]F"";
;;f$
K
$$$[$??
 F
 	

 Y//
 t..y99
 t''Y??
 
 4
 4##K??
 T
 t
 D
 d&&{H==
 
  d33D4D4D[RY4Z4Z[[!
" t((lCC#
$   ))'22 )
 
 
 	
r8  c                     i ddddddddddd	dd
d
dddddddddddddddddd}|                      |||          S )Nunknownr  
confirmingpending	confirmedr<  safeorphanr^  rZ  	reexaminerejectpasszwallet-rejectzconfirm-errorrepealedzwallet-transferzpre-transfer	verifyingrf  rg  s      r7  rR  zhtx.parse_transaction_status  s    
x
 )
 	

 D
 h
 
 

 
 h
 I
 X
 X
  !
" y#
$ I%
& '
* &&999r8  r  r!  c                 (   |                      ||          \  }}|                                  |                     |           |                     |          }||d                                         d}|||d<   d}|                     |          \  }}||                     ||          |d<   t          |                     |||                    }| 	                    | j
        di           }	|                     |	dd          rG|                     |d	          }
|
|                                 }|                     |                     | j        |                    | _        | 	                    |d
         |i           }|                     |d	          }
|
t#          | j        dz             |                     ||
|          }|                     |d	          }|                     |          }t+          j        ||          }t          |          }t          |          |d	<   t          |                     |||                    }||d<   |                     |                     ||                    }|                     ||          S )a  

        https://www.htx.com/en-us/opend/newApiPages/?id=7ec4cc41-7773-11ed-9966-0242ac110003

        make a withdrawal
        :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  rH  Nzaddr-tagr  r   r  Frb  r'  z withdraw() function can not find withdraw fee for chosen network. You need to re-load markets with "exchange.loadMarkets(True)", or provide the "fee" parameterr  )handle_withdraw_tag_and_paramsrF  r"  rH  r  r,  r  floatcurrency_to_precisionrP  r  r  ri  r  map_to_safe_mapr0  
currenciesr*   r=   r  r  r8   
string_sub$spotPrivatePostV1DwWithdrawApiCreatero  rT  )r5  r  r  r  r!  rR  rH  rp  r  withdrawOptionsrb  rf  targetNetwork	feeStringrS  amountSubtractedStringamountSubtractedrU  s                     r7  r   zhtx.withdraw  s    99#vFFV7###==&& ,,..
 
 ?"%GJ"AA&IIV"#66{DIIGGt11$LLMM//$,
BGG>>/<?? 	\""6511C{!2244
"&"6"6t7G7GYc7d7d"e"e $0DkSU V V&&}e<<;+DG  7Y  -Y  Z  Z  Z224kJJIYYvu--F0088L%,%7i%P%P"$%;<<"9--GEN455d<LkZZ[[F"<<T[[RX=Y=YZZ %%h999r8  r   c           
      r    |                      |d          }|                     d |          }||d d |d d d d d	S )Nr]  )	rE  r=   r  rY  rH  r  fromAccount	toAccountr   )rI  r  )r5  r   rH  r=   r  s        r7  parse_transferzhtx.parse_transfer>  sX     h//&&tX66

 

 
	
r8  ro  rp  c                    |                                   |                     |          }|d         t          |                     ||                    d}d}|                     dd|          \  }}|                     |          }	|                     |          }
|
dk    }|	dk    }|                     |
| j                  }|                     |	| j                  }|	dk    }|
dk    }|r"|r t          | j	        dz   |z   dz   |z             |	d	k    p|
d	k    }d}|rO|	d
z   |
z   }| 
                    |d|          }||d<   |                     |                     ||                    }nd|r-|r+|                     |                     ||                    }n5|r-|r+|                     |                     ||                    }n|r1|r/|
|d<   |                     |                     ||                    }n|r1|r/|	|d<   |                     |                     ||                    }n|dk    r_|	dk    s|dk    rd}	nd}
| 
                    |d          }|                     |d          }||                     |          }||d<   nd|d<   |rdn|	|d<   |rdn|
|d<   |                     |                     ||                    }|                     ||          S )a  
        transfer currency internally between wallets on the same account

        https://huobiapi.github.io/docs/dm/v1/en/#transfer-margin-between-spot-account-and-future-account
        https://huobiapi.github.io/docs/spot/v1/en/#transfer-fund-between-spot-account-and-future-contract-account
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-transfer-margin-between-spot-account-and-usdt-margined-contracts-account
        https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-spot-trading-account-to-cross-margin-account-cross
        https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-spot-trading-account-to-isolated-margin-account-isolated
        https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-cross-margin-account-to-spot-trading-account-cross
        https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-isolated-margin-account-to-spot-trading-account-isolated

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from 'spot', 'future', 'swap'
        :param str toAccount: account to transfer to 'spot', 'future', 'swap'
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.symbol]: used for isolated margin transfer
        :param str [params.subType]: 'linear' or 'inverse', only used when transfering to/from swap accounts
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        r=   rH  r  Nr   rl  rJ   z+ transfer() cannot make a transfer between z and r  z-to-r\  re  r   rO   zlinear-swapzmargin-accountr&  rM   r  r  )rF  rH  rc  rd  r  convert_type_to_accountin_arrayr  r+   r=   rI   spotPrivatePostV1FuturesTransferro   privatePostCrossMarginTransferIn!privatePostCrossMarginTransferOutprivatePostDwTransferInMarginprivatePostDwTransferOutMarginr  rw  v2PrivatePostAccountTransferrq  )r5  r  r  ro  rp  rR  rH  rp  r;  fromAccountIdtoAccountIdtoCross	fromCross
toIsolatedfromIsolatedfromSpottoSpotfromOrToFuturesAccountrU  r\  re  s                        r7  r   zhtx.transferU  sg   * 	==&& D66tVDDEE
 
 99*dFSS44[AA229==(!W,	]];99
}}]DH== E)% 	z 	zTW'TTWbbelloxxyyy"/9"<![+QZBZ! 	W 6)K7D##FFD99D"GFO<<T[[RX=Y=YZZHH 	W' 	W<<T[[RX=Y=YZZHH 	W6 	W==dkk'SY>Z>Z[[HH 	W* 	W +GH99$++gv:V:VWWHH 	Wf 	W -GH::4;;wPV;W;WXXHH(""!V++1M1M$1MM"/K))&(;;6844%!^^F33F06G,--06G,-(0CffmGFO&,=FF+GDM88Wf9U9UVVH ""8X666r8  c                     |                                   |                     |          }|                     |dg           }|                     |          S )av  
        fetch the borrow interest rates of all currencies

        https://huobiapi.github.io/docs/spot/v1/en/#get-loan-interest-rate-and-quota-isolated

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `isolated borrow rate structures <https://docs.ccxt.com/?id=isolated-borrow-rate-structure>`
        r]  )rF  spotPrivateGetV1MarginLoanInforP  parse_isolated_borrow_ratesr  s       r7  fetch_isolated_borrow_rateszhtx.fetch_isolated_borrow_rates  sT     	66v>>< x44//555r8  rE  c           
         |                      |d          }|                     ||          }|                     |dg           }|                     |d          }|                     |d          }|                      |d          }|                      |d          }	||                     |          |                     |d          |                     |	          |                     |d          dd d |d	S )	Nre  rf  r   r   rH  zactual-ratei \&)	re  r  baseRater  	quoteRater  r  rY  rE  )rI  rh  rP  r  ri  )
r5  rE  rc  rj  re  rf  baseData	quoteDatar  r  s
             r7  parse_isolated_borrow_ratezhtx.parse_isolated_borrow_rate  s    0 ##D(33!!(F33__T<<<
??:q11OOJ22	!!(J77""9j99++F33((=AA,,W55)))]CC

 

 
	
r8  c                 v   |t          | j        dz             d}|                     |dd          \  }}|r|                     d||||dddd		  	        S |                                  |                     |          }d
|d         i}|||d<   nd	|d<   d}|d         r*|                     |                     ||                    }nI|d         r*|                     |                     ||                    }nt          | j        dz             | 
                    |d          }	| 
                    |	d          }
| 
                    |	dg           }g }t          dt          |                    D ]}||         }|
|d<   |                     |d
          }|                     |          }|                     |d          }|                    |||                     |d          ||                     |          d           |                     |d          }|                     ||d         ||          S )a  

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-historical-funding-rate
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-historical-funding-rate

        fetches historical funding rate prices
        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: not used by huobi, but filtered internally by ccxt
        :param int [limit]: not used by huobi, but filtered internally by ccxt
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :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>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentFr   rd  current_page
page_indexr   r   r  r=   rk  r   r   zA fetchFundingRateHistory() supports inverse and linear swaps onlyr]  r   funding_timefunding_rate)rE  re  fundingRater  rY  r  re  )r*   r=   r  fetch_paginated_call_cursorrF  rc  3contractPublicGetSwapApiV1SwapHistoricalFundingRatero  9contractPublicGetLinearSwapApiV1SwapHistoricalFundingRater0   rP  rt  ru  rI  rh  r  r  ri  r  r~  r  )r5  re  r\  r  rR  rd  rc  rp  rU  r]  cursorrx  ratesry  r*  rj  symbolInnerr  sorteds                      r7  fetch_funding_rate_historyzhtx.fetch_funding_rate_history  s    >#DG.e$efff88AZ\fgg& 	R334MvW\^cekm{  ~J  LM  OQ  R  R  RV$$VD\
 #(GK  #%GK ) 	nOOPTP[P[\cekPlPlmmHHH 	nUUVZVaVabikqVrVrssHHtw)llmmm. x00~66vr22q#f++&& 	 	A1IE$*E.!''??H**844K))%@@ILL%#//~FF& LL33      e[11009I5RWXXXr8  c                 l   |                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }t          j        ||          }|                     |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|                     |          iS )Nestimated_rater  next_funding_timer  rE  re  	markPrice
indexPriceinterestRateestimatedSettlePricer  rY  r  r  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)ri  r  rI  r8   rg  rh  r  parse_funding_interval)r5  r   rc  r  r  r  fundingTimeStringnextFundingTimeStringmillisecondsIntervalrj  re  s              r7  parse_funding_ratezhtx.parse_funding_rateM  s     **85EFF,,X~FF#00;NOO ,,X~FF $ 0 0;N O O&12GIZ[[##Ho>>!!(F33
H
f
 
 $	

 D
 #D
 
 
 4++HnEE
  0
 t||,<==
 
 #$8
 "4<<0D#E#E
 "4
  '!
" &t#
$ 334HII%
 
 	
r8  c                 @    dddddd}|                      |||          S )Nr   r   8h16h24h)360000014400000288000005760000086400000rf  )r5  r  	intervalss      r7  r  zhtx.parse_funding_intervalz  s7    
 
	 	8X>>>r8  c                    |                                   |                     |          }d|d         i}d}|d         r*|                     |                     ||                    }nI|d         r*|                     |                     ||                    }nt          | j        dz             |                     |di           }|                     ||          S )a  
        fetch the current funding rate

        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-funding-rate
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        r  r=   Nr   r   z: fetchFundingRate() supports inverse and linear swaps onlyr]  )	rF  rc  )contractPublicGetSwapApiV1SwapFundingRatero  /contractPublicGetLinearSwapApiV1SwapFundingRater0   r=   rP  r  )r5  re  rR  rc  rp  rU  rx  s          r7  fetch_funding_ratezhtx.fetch_funding_rate  s     	V$$VD\
 ) 	gEEdkkRY[aFbFbccHHH 	gKKDKKX_agLhLhiiHHtw)eefff  6266&&vv666r8  c                    |                                   |                     |          }|                     | j        dd          }d}|                     |dd|          \  }}|9|                     |d          }|                     |          }|d         }|rdnd}i }d}	|dk    r*|                     |                     ||                    }	nG|dk    r*|                     |                     ||                    }	nt          | j
        dz             |                     |	d	g           }
|                     |
|          S )
a!  
        fetch the funding rate for multiple markets

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-a-batch-of-funding-rate
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-a-batch-of-funding-rate

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rates-structure>`, indexed by market symbols
        r  r   Nr   r;  r   r   z1 fetchFundingRates() not support self market typer]  )rF  r  rI  r  r  rc  4contractPublicGetLinearSwapApiV1SwapBatchFundingRatero  .contractPublicGetSwapApiV1SwapBatchFundingRater0   r=   rP  parse_funding_rates)r5  rm  rR  r  r;  firstSymbolrc  isLinearrp  rU  r]  s              r7  fetch_funding_rateszhtx.fetch_funding_rates  s`    	%%g..))$,8H(SS77@SU^`noo**7A66K[[--Fh'H"*9hh	G
 hPPQUQ\Q\]dflQmQmnnHH	!!JJ4;;W^`fKgKghhHHtw)\\]]]& x44''g666r8  c                 |   |                                   d}|                     d|          \  }}|dn|}i }||                     |          |d<   |||d<   d}d}	|dk    rL| |                     |          }|d         |d<   |                     |                     ||                    }	nK| |                     |          }
|
d         |d	<   |                     |                     ||                    }	|                     |	d
          }| 	                    ||          }| 
                    ||||          S )a  
        fetch the interest owed by the user for borrowing currency for margin trading

        https://huobiapi.github.io/docs/spot/v1/en/#search-past-margin-orders-cross
        https://huobiapi.github.io/docs/spot/v1/en/#search-past-margin-orders-isolated

        :param str code: unified currency code
        :param str symbol: unified market symbol when fetch interest in isolated markets
        :param int [since]: the earliest time in ms to fetch borrrow interest for
        :param int [limit]: the maximum number of structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/?id=borrow-interest-structure>`
        Nrl   rl  z
start-datere  rm  r=   re  rH  r]  )rF  rs  yyyymmddrc  privateGetMarginLoanOrdersro  rH  privateGetCrossMarginLoanOrdersrP  parse_borrow_interestsfilter_by_currency_since_limit)r5  r  re  r\  r  rR  r  rp  rc  rU  rH  r]  interests                r7  fetch_borrow_interestzhtx.fetch_borrow_interest  s]    	
!??@UW]^^
F!+!3WW*
$(MM%$8$8GL!#GFO##!V,,$*4L!66t{{7F7S7STTHH==..&.tn
#;;DKKQW<X<XYYH. x00..tV<<228T5%PPPr8  c                    |                      |d          }|dnd}|                     |          }|                      |d          }|                     |d          }|||                     |                      |d                    |                     |d          |                     |d          |                     |d          |||                     |          d		S )
Nre  rl  rm  z
accrued-atrH  zinterest-amountzinterest-ratezloan-amount)	rE  re  rH  r  r  amountBorrowedr  r  rY  )rI  r)  r  r  ri  r  )r5  rE  rc  rj  r  re  r  s          r7  parse_borrow_interestzhtx.parse_borrow_interest  s    T ##D(33!)!1WW

!!(++!!&(33%%dL99	//0@0@z0R0RSS((/@AA ,,T?CC"..t]CC$"Y//

 

 
	
r8  c                 F    |                                  | j        d         z
  S )Nr  )millisecondsr  )r5  s    r7  r1  z	htx.nonceY  s!      ""T\2B%CCCr8  r   r  c                 x   d}|                      ||                     |                    }t          |t                    r|dk    s|dk    r|| j        z  }n|dk    s|dk    r|dz  }|d|                     ||          z   z  }|dk    s|dk    rD|                                  |                     |                                 d          }	dd	| j	        |	d
}
|dk    r| 
                    |
|          }
|                     |
          }|                     |d          }d                    || j        ||g          }|                     |                     |          |                     | j                  t$          j        d          }|d|                     d|i          z   z  }|d|z   z  }|dk    r|                     |          }ddi}n"ddi}n|r|d|                     |          z   z  }|                     | j        d         |         d| j        i          |z   }n|                     |d          }|                     |d          }|                     |d          }|                     |d          }d }|                     | j        d         |          }t          |t                    sC|                     ||          }t          |t                    s||                     ||          }|}||                     ||          z  }|dk    r|r|d|                     |          z   z  }nO|dk    rH|                                  |dk    r|                     | j        di           }|                     |dd          }|                    d          d k    r3|                    d!          r|                     |d"          }|||d"<   nG|                    d#          r2|                     |d$          }|||                                 z   |d$<   |                     |                                 d          }	dd	| j	        |	d
}
|                     |
          }
|dk    r+|                     |          }| 
                    |
|          }
|                     |
d                              d%d&          }d                    ||||g          }|                     |                     |          |                     | j                  t$          j        d          }|d|                     d|i          z   z  }|d|z   z  }|dk    r/|                     |          }t;          |          dk    rd'}ddi}nddi}|                     | j        d         |         d|i          |z   }||||d(S ))Nr  r   r   r   r   v2T
HmacSHA256r_  )SignatureMethodSignatureVersionAccessKeyId	TimestampPOSTT
base64&	Signature?zContent-Typezapplication/jsonz!application/x-www-form-urlencodedr   rI   r   r   r  r  r   r  r=   r  cancelrJ  r  zorders/placerp  z%2cz%2Cz{})r   r  bodyheaders)r  extract_paramsr  r  rG   implode_paramscheck_required_credentialsymdhmsr1  apiKeyro  keysort	urlencoder  rI   hmacencodesecrethashlibsha256r  r   rI  rP  r  rN  endswithr  r  ru  )r5  pathr   r  rR  r  r  r   queryr  rp  sortedRequestauthpayload	signaturer\  accesslevelOneNestedPathlevelTwoNestedPathrI   r   r  r=   channelCoder  sortedQuerys                             r7  signzhtx.sign\  s
   		&$"5"5d";";<<c3 h	xSI%5%5t|###););t3,,T6::::Ci3+#5#5//111 KK

c::	'3(+#';!*	! ! V##"kk'599G $W 5 5~~mT::))VT]C$FGG IIdkk'&:&:DKK<T<TV]Vdfnoo	dnnk9-EFFFFsTz!V##99U++D&(:GG
 '(KGG  73!6!666C%%di&6s&;DM>  CC ##C++D%%c1--F!%!1!1#q!9!9!%!1!1#q!9!9H	+(>EEIi-- O OOI7IJJ	"9c22 O9K9W $	;M N NI H4&&tV444C!! 73!6!666C9$$//111V##"oodlHbIIG))'4FFByy**b00T]]75K5K0&*&6&6v~&N&N&.57F>2~66 I(,(8(8AR(S(S(08:TYY[[8HF#45 KK

c::	'3(+#';!*	! ! ,,w//V##"&,,u"5"5K"kk';??G~~gt44<<UEJJ))VXsD$ABB IIdkk'&:&:DKK<T<TV]Vdfnoo	dnnk9-EFFFFsTz!V##99U++D4yyA~~#&(:GG
 '(KG %%di&6t&<H?  C fdwOOOr8  httpCodereasonr   r  r  r  c
                    |d S d|v r|                      |d          }
|
dk    r|                     |dd          }| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           |                     |dd	          }|                     | j        d         ||           t          |          d
|v rE| j        dz   |z   }|                      |d
          }|                     | j        d         ||           |                     |d          }|                     |d          }||                     |d          }|                      |d          }|                      |d	          }| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           d S )Nr   errorrl  rk  r  r  r  zerr-msgerr_msgr  r]  r  r   )	rI  r  r=   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr&   r  r  )r5  r  r   r   r  r  r  rU  requestHeadersrequestBodyr   r  feedbackmessager]  
errorsListrq  errcode
errmessagefeedBacks                       r7  handle_errorszhtx.handle_errors  s   4x
 %%h99F  ))(J
KK7S=4/44T_W5MtU]^^^44T_W5MtU]^^^,,Xy)LL44T_W5MwX`aaa#H---Xw}t+H##Hf55D001I4QYZZZ~~h//^^D(33
!NN:q11E&&uj99G))%;;Jw}t+H001I7T\]]]001I:W_```tr8  c                    |                                   |                     |          }|                     d||          \  }}ddi}|||d<   d}	|dk    r|d         |d<   |d	         rhd}
|                     d|          \  }
}|
d
n|
}
|
dk    r|d         |d<   n|d         |d<   |                     |                     ||                    }	n^|                     |                     ||                    }	n4|d         |d<   |                     |                     ||                    }	|                     |	dg           }| 	                    ||||          S )a  
        fetch the history of funding payments paid and received on self account

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-account-financial-records-via-multiple-fields-new   # linear swaps
        https://huobiapi.github.io/docs/dm/v1/en/#query-financial-records-via-multiple-fields-new                          # coin-m futures
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-financial-records-via-multiple-fields-new          # coin-m swaps

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding history structure <https://docs.ccxt.com/?id=funding-history-structure>`
        r}   r\  z30,31N
start_daterO   r=   r   r   rl  rm  mar_acctr  re  r]  )
rF  rc  rG  rs  :contractPrivatePostLinearSwapApiV3SwapFinancialRecordExactro  4contractPrivatePostSwapApiV3SwapFinancialRecordExact4contractPrivatePostApiV3ContractFinancialRecordExactr  parse_incomes)r5  re  r\  r  rR  rc  rS  r  rp  rU  r  r]  s               r7  fetch_funding_historyzhtx.fetch_funding_history  s    	V$$ >>?TV\^dee
EG
 $)GL!"(,GJh 4r. "
%)%G%GH]_e%f%f"
F)3);WW*
++*0,GJ''*0*;GJ'ZZ[_[f[fgnpu[v[vww,  TTUYU`U`ahjoUpUpqq &tGHPPQUQ\Q\]dfkQlQlmmH~~h33!!$u===r8  r  c                 B   |t          | j        dz             |                                  |                     |          }|                     d||          \  }}d|i}|dk    r|d         r|d         |d<   n|d	         |d
<   d}|d         rd}	|                     d|          \  }	}|	dn|	}	|	dk    r*|                     |                     ||                    }n|	dk    r*|                     |                     ||                    }nt          | j        dz             |dk    r*| 
                    |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j        dz             |S )am  
        set the level of leverage for a market

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-switch-leverage
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-switch-leverage
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#switch-leverage
        https://huobiapi.github.io/docs/dm/v1/en/#switch-leverage  # Coin-m futures

        :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   r  rP   r   r  re  r=   r  r   rl  rm  + setLeverage() not support self market typerO   )r*   r=   rF  rc  rG  rs  5contractPrivatePostLinearSwapApiV1SwapSwitchLeverRatero  :contractPrivatePostLinearSwapApiV1SwapCrossSwitchLeverRater0   /contractPrivatePostApiV1ContractSwitchLeverRate/contractPrivatePostSwapApiV1SwapSwitchLeverRate)
r5  r  re  rR  rc  rS  r  rp  rU  r  s
             r7  set_leveragezhtx.set_leverage?  s    >#DG.Y$YZZZV$$ >>}fV\]]
E(
 !!fY&7! &z 2GH'-d|GO$( 	\J!%!C!CMSY!Z!ZJ%/%7jJZ''UUVZVaVabikpVqVqrrw&&ZZ[_[f[fgnpu[v[vww"47-Z#Z[[[ X%%OOPTP[P[\cejPkPkllv%%OOPTP[P[\cejPkPkll"47-Z#Z[[[" r8  c                 p   |                      |d          }|                     ||          }|                     |d          }|                     |d          }|                      |d          }|                     |dd          }|                     |          }	|||	||                     |          ||dS )Nr  r  r>  r=   re  asset)rE  re  r  r  rY  r=   r  )rI  rh  ri  r  r  r  r  )
r5  incomerc  rj  re  r  r  r=   r  r  s
             r7  parse_incomezhtx.parse_income  s     ##FO<<!!(F33!!&(33%%fd33	fd++'''BB
&&z22"Y//
 
 	
r8  positionc                 j   |                      |                     |d                    }|d         }|                     |d          }|                     |d          }|                     |          }|                     |d          }|                     |d          }|                     |d          }	|	dk    rd	nd
}
|                     |d          }|                     |d          }|                     |d          }t          j        |                     |d          d          }|                     |d          }t          j        ||          }d }|d         rt          j        ||          }nt          j        ||          }d}t          j        ||          }|                     |d          }|                     |d          }|                     |d          }t          j        ||          }t          j        ||          }t          j        ||          }|                     i d|dd d|d| 	                    |          d|d|d| 	                    |          d|
d|d| 	                    |          d| 	                    |          d|d | 	                    |          d!d d"d d#|d$| 	                    |          | 	                    |          | 	                    |          | 	                    |          | 	                    |          d d d d d d d%
          S )&Nr  re  rr  r  	cost_openposition_marginr'  r  longshortprofit_unrealmargin_moder  profit_rater  
last_pricer   rl  r  liquidation_priceadjust_factorrE  r=   	contracts
entryPrice
collateralr(  unrealizedPnlr  r   r  notionalr  	lastPriceliquidationPriceinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior  rY  r  lastUpdateTimestampr  r  )
r)  rI  rP  r  ri  r8   r  r  safe_positionr4  )r5  r"  rc  re  r.  r  contractSizeStringr/  r5  rawSider(  unrealizedProfitr  r  r   r3  	faceValuer2  intialMarginPercentager0  r4  adjustmentFactorr8  r7  r9  s                            r7  parse_positionzhtx.parse_position  s   @ !!$"2"28_"M"MNN!$$Xx88	v~>>!22<@@%%h<<
((3DEE""8[99!U**vv++HoFF%%h>>
##Hl;;'(8(8=(Q(QSXYY
$$X|<<	&y2DEE	( 	!))Y??HH))Y??H J!(!3M8!L!L%%h0@AA
++H6IJJ++HoFF&-&89I8&T&T##./JHUU():JGG!! #
H#
$#
 f#
 **955	#

 L#
 *#
 $++J77#
 D#
 -#
 ))(33#
 $++J77#
 *#
 ))(33#
 #
 #
   0!#
" T..}==##
$ (,'8'89O'P'P!%!2!23D!E!E+/+<+<=X+Y+Y,,[99#'!#7#
 #
 #
   	r8  c           
      h   |                                   |                     |          }d}|@t          |          }|dk    r+|                     |d          }|                     |          }d}|                     d|d          \  }}d}|                     d||d          \  }}d}|                     d||          \  }}|dk    rd}d}	|dk    rO|dk    r|                     |          }	n|dk    r| 	                    |          }	nft          | j        d	z             |dk    r|                     |          }	n3|d
k    r|                     |          }	nt          | j        d	z             |                     |	dg           }
|                     |	d          }g }t!          dt          |
                    D ]^}|
|         }|                     |          }|                    |                     |||                     |          d                     _|                     |d|d          S )as  
        fetch all open positions

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-query-user-39-s-position-information
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-query-user-s-position-information
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-user-s-position-information
        https://huobiapi.github.io/docs/dm/v1/en/#query-user-s-position-information

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: 'linear' or 'inverse'
        :param str [params.type]: *inverse only* 'future', or 'swap'
        :param str [params.marginMode]: *linear only* 'cross' or 'isolated'
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr   r   rl  r   rM   rP   rm  z. fetchPositions() not support self market typerO   r]  r>  r  rY  re  F)rF  r  ru  rI  rc  rs  r  rG  2contractPrivatePostLinearSwapApiV1SwapPositionInfo7contractPrivatePostLinearSwapApiV1SwapCrossPositionInfor0   r=   ,contractPrivatePostApiV1ContractPositionInfo,contractPrivatePostSwapApiV1SwapPositionInforP  r  rt  rB  r  ro  r  filter_by_array_positions)r5  rm  rR  rc  symbolsLengthrq  r  r;  rS  rU  r]  r  rx  ry  r"  r)  s                   r7  fetch_positionszhtx.fetch_positions  s     	%%g..LLMq  ((!44U++
!??@PRXZabb
F99:JFTZ\dee
!??@PRXZ`aa
F!JhZ''RRSYZZw&&WWX^__"47-]#]^^^: X%%LLVTTv%%LLVTT"47-]#]^^^f x44%%h55	q#d))$$ 	 	AAwH((22FMM$++f& LL33/ /       --fhOOOr8  c                 t   |                                   |                     |          }d}|                     d|          \  }}|dn|}|                     d||          \  }}i }|d         r|d         r|d         |d<   n|dk    rd|d	<   |d
         |d<   d}|d         rw|dk    r*|                     |                     ||                    }n|dk    r*|                     |                     ||                    }nt          | j        dz             |dk    r*| 	                    |                     ||                    }nG|dk    r*| 
                    |                     ||                    }nt          | j        dz             |                     |d          }	d}
|dk    r|	}
n|                     |	d          }
|                     |
dg          }|                     |
d          }d}|d         rG|d         r?t          dt          |                    D ] }||         }|d         |d
         k    r|} n!n|                     |d          }|                     |d          }|                     |                     ||                    }||d<   |                     |          |d<   |S )a  
        fetch data on a single open contract trade position

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-query-assets-and-positions
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-query-assets-and-positions
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-assets-and-positions
        https://huobiapi.github.io/docs/dm/v1/en/#query-assets-and-positions

        :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
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr   rl  rP   r   r  re  r&  r  r=   r  r   rm  z- fetchPosition() not support self market typerO   r  r]  r   	positionsr>  r  rY  )rF  rc  rs  rG  9contractPrivatePostLinearSwapApiV1SwapAccountPositionInforo  >contractPrivatePostLinearSwapApiV1SwapCrossAccountPositionInfor0   r=   3contractPrivatePostApiV1ContractAccountPositionInfo3contractPrivatePostSwapApiV1SwapAccountPositionInforP  r  rt  ru  r  rB  r  )r5  re  rR  rc  r  rS  r  rp  rU  r]  r  omittedrM  r"  ry  r*  r  r)  s                     r7  fetch_positionzhtx.fetch_position  s    	V$$
!??QWXX
F!+!3WW*
 >>PVX^__
E( 	4y 1 	4 &z 2GHW$$,2()'-d|GO$( B	\Z''YYZ^ZeZefmotZuZuvvw&&^^_c_j_jkrty_z_z{{"47-\#\]]]n X%%SSTXT_T_`ginToToppv%%SSTXT_T_`ginToTopp"47-Z#Z[[[L x00  GGoodA..G))Gk]33OOG[99	( 	5y 1 	51c)nn--  !!)VD\99$HE : y!44H%%h55	$$T[[7%C%CDD'{!\\)44zr8  c                 R    ddddddddddddddd	}|                      |||          S )
Nr8  rb  r   creditr  rF  exchangerebate)r8  etfztransact-feezfee-deductionr   rU  liquidationr  r  r   zwithdraw-feerV  zother-typesrW  rf  )r5  r\  r  s      r7  parse_ledger_entry_typezhtx.parse_ledger_entry_type  sR    !"""  $!"%
 
  tT222r8  itemc                    |                      |d          }|                     ||          }|                     ||          }|                      |d          }|                      |d          }|                     |d          }|                      |d          }|                     |||                      |d          ||||                     |          ||                     |d          ||                     |          d d d d d|          S )	NrH  
transactIdtransferTypetransactTimer  r'  transactAmt)rE  r=   r'  r  referenceIdreferenceAccountr\  rH  r  r  rY  beforeafterr   rb  )rI  r  r  r  safe_ledger_entryrZ  ri  r  )	r5  r[  rH  r  r  r=   r^  r  r  s	            r7  parse_ledger_entryzhtx.parse_ledger_entry  s%    %%dJ77
&&z8<<%%j(;;dL11''n==%%dN;;	""455%%))$<< '00>>&&t];;"Y//'
 '
  !  	r8  c                    |                                   d}|                     |dd          \  }}|r|                     d||||d          S |                     ddd|          }d|i}d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                    }	|                     |	dg           }
| 	                    |
|||          S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://huobiapi.github.io/docs/spot/v1/en/#get-account-history

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `ledger structure <https://docs.ccxt.com/?id=ledger-entry-structure>`
        Fr   rd  r  rM   Nr  r=   rH  	startTimer  endTimer]  )
rF  r  rp  r  rH  rq  spotPrivateGetV2AccountLedgerro  rP  parse_ledger)r5  r  r\  r  rR  rd  r  rp  rH  rU  r]  s              r7  fetch_ledgerzhtx.fetch_ledger  sA    	88PZ[[& 	e44]D%QVX^`cddd11&$fMM		
 }}T**H"*4.GJ#(GK $GG229gvNN55dkk'66R6RSSB x44  x>>>r8  c                     |                                   |                     |          }|                     |dg           }|                     ||d          S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/?id=leverage-tiers-structure>`, indexed by market symbols
        r]  r  )rF  0contractPublicGetLinearSwapApiV1SwapAdjustfactorr  parse_leverage_tiers)r5  rm  rR  rU  r]  s        r7  fetch_leverage_tierszhtx.fetch_leverage_tiers  sX     	HHPP< ~~h33((wHHHr8  c                 2   |                      |d          }|                      |d          }g }|                     |dg           }t          dt          |                    D ]2}||         }|                      |d          }	|                     |dg           }
t          dt          |
                    D ]}|
|         }|                      |d          }|                    |                     |d          |                     ||d d	          |                     |          |                     |d
          |                     |d          | 	                    t          j        ||	                    | 	                    |	          |d           ݐ4|S )Ntrade_partitionr  r  r   r  laddersr-  ladderrO   min_sizemax_size)tierre  rH  minNotionalmaxNotionalmaintenanceMarginRatemaxLeveragerE  )rI  r  rt  ru  r  r  rh  r  ri  r4  r8   r  )r5  rE  rc  r  rj  tiersbracketsry  r[  r  rs  kbracketadjustFactors                 r7  parse_market_leverage_tierszhtx.parse_market_leverage_tiers.  s   %%d,=>>
##D/::>>$33q#h--(( 	 	AA;D''l;;HnnT9b99G1c'll++  !!*#//II --gx@@"..xvNN $ 7 7
 C C#'#3#3GZ#H#H#'#3#3GZ#H#H-1->->w?QR^`h?i?i-j-j#'#4#4X#>#>#	 	 	 	 	 	 r8  r   c                 Z   |dk    r)|dk    r#|dk    r|dk    rt          | j        dz             |                                  dddd	d
}|                     |          }|                     |ddd          }||         |d}	|||	d<   d}
|d         rT|                     |d         d          |	d<   |d         |	d<   |                     |                     |	|                    }
n|d         rEd|	d<   |d         |	d<   |d         |	d<   |                     |                     |	|                    }
n4|d         |	d<   | 	                    |                     |	|                    }
| 
                    |
d          }|                     |d          }|                     ||||          S )u  
        Retrieves the open interest history of a currency

        https://huobiapi.github.io/docs/dm/v1/en/#query-information-on-open-interest
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-information-on-open-interest
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-information-on-open-interest

        :param str symbol: Unified CCXT market symbol
        :param str timeframe: '1h', '4h', '12h', or '1d'
        :param int [since]: Not used by huobi api, but response parsed by CCXT
        :param int [limit]: Default：48，Data Range [1,200]
        :param dict [params]: Exchange specific parameters
        :param int [params.amount_type]: *required* Open interest unit. 1-cont，2-cryptocurrency
        :param int [params.pair]: eg BTC-USDT *Only for USDT-M*
        :returns dict: an array of `open interest structures <https://docs.ccxt.com/?id=open-interest-structure>`
        r   r   12hr   zJ fetchOpenInterestHistory cannot only use the 1h, 4h, 12h and 1d timeframer   r   12hourr   )r   r   r  r   amount_type
amountTyper  )r  r  Nre  rP   rE  r  r  re  r   rO   r=   r  r]  r
  )r+   r=   rF  rc  r`  rI  -contractPublicGetApiV1ContractHisOpenInterestro  3contractPublicGetLinearSwapApiV1SwapHisOpenInterest-contractPublicGetSwapApiV1SwapHisOpenInterestrP  r  parse_open_interests_history)r5  re  r  r\  r  rR  r   rc  r  rp  rU  r]  r
  s                r7  fetch_open_interest_historyzhtx.fetch_open_interest_historyF  s   " d!2!2yE7I7Ii[_N_N_TW'ssttt	
 

 V$$((aPP
 +%
 
 #GFO( 	h'+'7'7v'X'XGO$ &x 0GHII$++V]_eJfJfggHHH 		h'-GO$'-d|GO$'-d|GO$OOPTP[P[\cekPlPlmmHH'-d|GO$II$++V]_eJfJfggHz x00~~dF++00vueLLLr8  c                    |                                   |                     |          }d}|@t          |          }|dk    r+|                     |d          }|                     |          }i }d}|                     d||d          \  }}d}|                     d||          \  }}d}	|dk    r*|                     |                     ||                    }	n^|dk    r*| 	                    |                     ||                    }	n.d|d<   | 
                    |                     ||                    }	|                     |	d	g           }
|                     |
|          S )
aZ  
        Retrieves the open interest for a list of symbols

        https://huobiapi.github.io/docs/dm/v1/en/#get-contract-open-interest-information
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-swap-open-interest-information
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-swap-open-interest-information

        :param str[] [symbols]: a list of unified CCXT market symbols
        :param dict [params]: exchange specific parameters
        :returns dict[]: a list of `open interest structures <https://docs.ccxt.com/?id=open-interest-structure>`
        Nr   r   r   rP   r   rO   r  r]  )rF  r  ru  rI  rc  r  rG  *contractPublicGetApiV1ContractOpenInterestro  *contractPublicGetSwapApiV1SwapOpenInterest0contractPublicGetLinearSwapApiV1SwapOpenInterestr  parse_open_interests)r5  rm  rR  rc  rJ  rq  rp  r;  rS  rU  r]  s              r7  fetch_open_interestszhtx.fetch_open_interests  s    	%%g..LLMq  ((!44U++99:NPVX^`hii
!??@TV\^dee
F!!FFt{{SZ\bGcGcddHH& 	!!FFt{{SZ\bGcGcddHH& (.GO$LLT[[Y`bhMiMijjH. ~~h33((w777r8  c                 0   |                                   |                     |          }|d         st          | j        dz             |d         rt	          | j        dz             d|d         i}d}|d         rT|                     |d	         d
          |d
<   |d         |d<   |                     |                     ||                    }n`|d         r/d|d
<   |                     |                     ||                    }n)| 	                    |                     ||                    }| 
                    |dg           }|                     |d         |          }|                     |d          }||d<   |                     |          |d<   |S )a;  
        Retrieves the open interest of a currency

        https://huobiapi.github.io/docs/dm/v1/en/#get-contract-open-interest-information
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-swap-open-interest-information
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-swap-open-interest-information

        :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=open-interest-structure:
        r   z3 fetchOpenInterest() supports contract markets onlyrQ   z> fetchOpenInterest() does not currently support option marketsr  r=   NrP   rE  r  r  re  r   rO   r]  r   r>  r  rY  )rF  rc  r+   r=   r0   rI  r  ro  r  r  rP  parse_open_interestr  r  )	r5  re  rR  rc  rp  rU  r]  openInterestr  s	            r7  fetch_open_interestzhtx.fetch_open_interest   s    	V$$j! 	^TW'\\]]]( 	ktw)iijjjVD\
 ( 	e'+'7'7v'X'XGO$ &x 0GHFFt{{SZ\bGcGcddHHH 	e'-GO$LLT[[Y`bhMiMijjHH FFt{{SZ\bGcGcddH| x44//Q@@%%h55	$-[!#'<<	#:#:Z r8  c                 >   |                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |                     ||          ||||||                     |          |d|          S )Nr>  rr  valuer  )re  r  r  openInterestAmountopenInterestValuer  rY  rE  )r  ri  rI  safe_open_interestrh  r  )r5  r  rc  r  r  r  rj  s          r7  r  zhtx.parse_open_interest{   s    j %%h55	!!(H55  733##Ho>>&&&&x88  "(!&"Y//	(
 	(
 	 	 		r8  c                 z   |                                   |                     |          }|                     |          }|d         |                     ||          |d         d}|                     |                     ||                    }|                     ||          }	|                     |	||d          S )aW  
        create a loan to borrow margin

        https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-isolated
        https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-cross

        :param str symbol: unified market symbol, required for isolated margin
        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/?id=margin-loan-structure>`
        r=   )rH  r  re  r  re  )rF  rH  rc  rd  privatePostMarginOrdersro  parse_margin_loan)
r5  re  r  r  rR  rH  rc  rp  rU  rD  s
             r7  borrow_isolated_marginzhtx.borrow_isolated_margin   s     	==&&V$$ 00v>>Tl
 

 //GV0L0LMM ,,Xx@@{{;)
 )
   	r8  c                 @   |                                   |                     |          }|d         |                     ||          d}|                     |                     ||                    }|                     ||          }|                     |d|i          S )a  
        create a loan to borrow margin

        https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-isolated
        https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-cross

        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/?id=margin-loan-structure>`
        r=   rs  r  )rF  rH  rd  privatePostCrossMarginOrdersro  r  )r5  r  r  rR  rH  rp  rU  rD  s           r7  borrow_cross_marginzhtx.borrow_cross_margin   s     	==&& 00v>>
 
 44T[[&5Q5QRR ,,Xx@@{{;f)
   	r8  c                    |                                   |                     |          }|                     dd||          }|d         |                     ||          |d}|                     |                     ||                    }|                     |dg           }	|                     |	d          }
|                     |
|          }|                     |||d          S )a  
        repay borrowed margin and interest

        https://huobiapi.github.io/docs/spot/v1/en/#repay-margin-loan-cross-isolated

        :param str symbol: unified market symbol
        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/?id=margin-loan-structure>`
        rM   rm  r=   rH  r  r  Datar   r  rF  rH  r  rd  v2PrivatePostAccountRepaymentro  rP  r  )r5  re  r  r  rR  rH  r  rp  rU  r]  loanrD  s               r7  repay_isolated_marginzhtx.repay_isolated_margin!  s     	==&&11&*ffUU	 00v>>"
 

 55dkk'66R6RSS x44tQ'',,T8<<{{;)
 )
   	r8  c                    |                                   |                     |          }|                     ddd|          }|d         |                     ||          |d}|                     |                     ||                    }|                     |dg           }|                     |d          }	|                     |	|          }
|                     |
d|i          S )	a  
        repay borrowed margin and interest

        https://huobiapi.github.io/docs/spot/v1/en/#repay-margin-loan-cross-isolated

        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/?id=margin-loan-structure>`
        rM   rl  Nr=   r  r  r   r  r  )r5  r  r  rR  rH  r  rp  rU  r]  r  rD  s              r7  repay_cross_marginzhtx.repay_cross_margin*!  s     	==&&11&'4PP	 00v>>"
 

 55dkk'66R6RSS x44tQ'',,T8<<{{;f)
   	r8  c                     |                      |d          }|                     |dd          |                     d |          d d ||                     |          |dS )N	repayTimerepayIdr]  )r=   rH  r  re  r  rY  rE  )r  r  r  r  )r5  rE  rH  r  s       r7  r  zhtx.parse_margin_loanP!  sk    , %%dK88	$$T9f==//h??"Y//
 
 	
r8  c                    |t          | j        dz             |                     |d          }|                     |dg          }|                     |          }i }|d         r|d         |d<   n|d         |d<   |||d	<   |||d
<   |||d<   d}|d         r\|d         r*|                     |                     ||                    }nS|                     |                     ||                    }n)|                     |                     ||                    }| 	                    |d          }	| 	                    |	d          }
| 
                    |
|          }|                     |d          S )u  
        Fetches historical settlement records

        https://huobiapi.github.io/docs/dm/v1/en/#query-historical-settlement-records-of-the-platform-interface
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-historical-settlement-records-of-the-platform-interface
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-historical-settlement-records-of-the-platform-interface

        :param str symbol: unified symbol of the market to fetch the settlement history for
        :param int [since]: timestamp in ms, value range = current time - 90 days，default = current time - 90 days
        :param int [limit]: page items, default 20, shall not exceed 50
        :param dict [params]: exchange specific params
        :param int [params.until]: timestamp in ms, value range = start_time -> current time，default = current time
        :param int [params.page_index]: page index, default page 1 if not filled
        :param int [params.code]: unified currency code, can be used when symbol is None
        :returns dict[]: a list of `settlement history objects <https://docs.ccxt.com/?id=settlement-history-structure>`
        Nz4 fetchSettlementHistory() requires a symbol argumentr  rP   r  re  r=   r  start_atrk  end_atrO   r   r]  settlement_recordr  )r*   r=   r  r  rc  5contractPublicGetLinearSwapApiV1SwapSettlementRecordsro  /contractPublicGetSwapApiV1SwapSettlementRecords/contractPublicGetApiV1ContractSettlementRecordsrP  parse_settlementsr~  )r5  re  r\  r  rR  r  rc  rp  rU  r]  settlementRecordsettlementss               r7  fetch_settlement_historyzhtx.fetch_settlement_historyq!  s   " >#DG.d$deee!!&'226G9--V$$( 	4 &x 0GH'-d|GO$"'GJ#(GK  %GH&> 	jh nUUVZVaVabikqVrVrssOOPTP[P[\cekPlPlmmKKDKKX_agLhLhiiHj x00??41DEE,,-=vFF||K555r8  codesc                     |                                   |                     |          }|                     |d          }|                     ||d          S )a{  
        fetch deposit and withdraw fees

        https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-currencies-v2

        :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]  rH  )rF  r  r  parse_deposit_withdraw_fees)r5  r  rR  rU  r]  s        r7  fetch_deposit_withdraw_feeszhtx.fetch_deposit_withdraw_fees!  sW     	::6BBJ ~~h////eZHHHr8  c                     |                      |dg           }|                     |          }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |          }	d }
d }|dk    r|                     |d          }
|
dd}n|                     |d	          }
|
d
d}|d d dd|d         |	<   |                     ||          }|S )Nr  r   r  withdrawFeeTypefixedr  F)rb  r   transactFeeRateWithdrawT)r   r  r'  )rP  deposit_withdraw_feert  ru  rI  r  ri  $assign_default_deposit_withdraw_fees)r5  rb  rH  r  rx  r  r  r  r  r  withdrawFeewithdrawResults               r7  parse_deposit_withdraw_feezhtx.parse_deposit_withdraw_fee"  sG   @ h33**3//q#f++&& 	Q 	QAJ((W==I"..z;LMMO11)<<KK!N'))"..z;PQQ&"'" "
 #..z;TUU&"&" "
 +"& / /F:{+ >>vxPPFFr8  c                    g }t          dt          |                    D ]}||         }|                     |d          }||                     |d          }||                     |          d}t          dt          |                    D ]I}	||	         }
|                     |
|          }|                    |                     ||                     J|                    |                     ||         |                     |S )Nr   r  settlement_timerD  )rt  ru  rP  r  r  parse_settlementr  ro  )r5  r  rc  rx  ry  
settlementr  r  timestampDetailsr  r[  parsedSettlements               r7  r  zhtx.parse_settlementsE"  s!   J q#k**++ 	M 	MA$QJ??:v66D --j:KLL	!* $Y 7 7* *  q#d)),, S SA7D'+'<'<T6'J'J$MM$++.>@P"Q"QRRRRS
 d33KNFKKLLLLr8  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||                     |          dS )Nr  r  settlement_price)rE  re  r  r  rY  )r  rI  rh  ri  r  )r5  r  rc  r  rj  s        r7  r  zhtx.parse_settlement|"  sz    0 %%j2CDD	##J@@&&x88%%j2DEE"Y//
 
 	
r8  c                    |                                   |                     |          }|                     |dd          }d|i}|||d<   |                     d||          \  }}d}|d         rg|d         |d<   |d	         r*|                     |                     ||                    }n|                     |                     ||                    }n`|d
         r5|d         |d<   |                     |                     ||                    }n#t          | j	        dz   |d         z   dz             | 
                    |dg           }	|                     |	|||          S )a6  
        retrieves the public liquidations of a trading pair

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-liquidation-orders-new
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-liquidation-orders-new
        https://huobiapi.github.io/docs/dm/v1/en/#query-liquidation-order-information-new

        :param str symbol: unified CCXT market symbol
        :param int [since]: the earliest time in ms to fetch liquidations for
        :param int [limit]: the maximum number of liquidation structures to retrieve
        :param dict [params]: exchange specific parameters for the huobi api endpoint
        :param int [params.until]: timestamp in ms of the latest liquidation
        :param int [params.tradeType]: default 0, linear swap 0: all liquidated orders, 5: liquidated longs; 6: liquidated shorts, inverse swap and future 0: filled liquidated orders, 5: liquidated close orders, 6: liquidated open orders
        :returns dict: an array of `liquidation structures <https://docs.ccxt.com/?id=liquidation-structure>`
        rh  r   Nri  rj  rO   r=   r   r   rP   re  z& fetchLiquidations() does not support r\  rA  r]  )rF  rc  r  rq  5contractPublicGetLinearSwapApiV3SwapLiquidationOrdersro  /contractPublicGetSwapApiV3SwapLiquidationOrders/contractPublicGetApiV3ContractLiquidationOrdersr0   r=   r  parse_liquidations)
r5  re  r\  r  rR  rc  	tradeTyperp  rU  r]  s
             r7  fetch_liquidationszhtx.fetch_liquidations"  s     	V$$%%flA>>	)
 $)GL!22:wOO&> 
	p"(,GJh nUUVZVaVabikqVrVrssOOPTP[P[\cekPlPlmmH 	p &tGHKKDKKX_agLhLhiiHHtw)QQTZ[aTbbennooo0 ~~h33&&tVUEBBBr8  c                    |                      |d          }|                     |d          }|                     ||                     ||          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          ||                     |          d	
          S )
Nr  r;  rr  r  r  r'  r  rB  )
rE  re  r.  r  r  r(  	baseValue
quoteValuer  rY  )rI  r  safe_liquidationrh  ri  r  r  )r5  rY  rc  rj  r  s        r7  parse_liquidationzhtx.parse_liquidation"  s    " ##KAA%%k<@@	$$&&x88))+x@@ ,,V^DD%%k7;;**;DD))+x@@**;8HII"Y//&
 &
   	r8  c                    |                                   |                     |          }|                     |d          }|d         st          | j        dz             |                     d|d           |d         |d}|||d	<   |d
         rI|                     |dd          }|t          | j        dz             |                     ||          |d<   | 	                    |g d          }d}|d
         r\|d         r*| 
                    |                     ||                    }n|                     |                     ||                    }nud}	|                     d|d          \  }	}|	dk    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     ||          S )a  
        closes open positions for a contract market, requires 'amount' in params, unlike other exchanges

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-lightning-close-order  # USDT-M(isolated)
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-lightning-close-position  # USDT-M(cross)
        https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-lightning-close-order  # Coin-M swap
        https://huobiapi.github.io/docs/dm/v1/en/#place-flash-close-order                      # Coin-M futures

        :param str symbol: unified CCXT market symbol
        :param str side: 'buy' or 'sell', the side of the closing order, opposite side side
        :param dict [params]: extra parameters specific to the okx api endpoint
        :param str [params.clientOrderId]: client needs to provide unique API and have to maintain the API themselves afterwards. [1, 9223372036854775807]
        :param dict [params.marginMode]: 'cross' or 'isolated', required for linear markets

 EXCHANGE SPECIFIC PARAMETERS
        :param number [params.amount]: order quantity
        :param str [params.order_price_type]: 'lightning' by default, 'lightning_fok': lightning fok type, 'lightning_ioc': lightning ioc type 'market' by default, 'market': market order type, 'lightning_fok': lightning
        :returns dict: `an order structure <https://docs.ccxt.com/?id=position-structure>`
        r  r   z6 closePosition() symbol supports contract markets onlyrZ   r(  r=   )r  r'  Nr  r   rr  r  zP closePosition() requires an extra argument params["amount"] for inverse markets)r  rr  r  rO   rl  )rF  rc  rI  r+   r=   check_required_argumentr  r*   r  r  6contractPrivatePostSwapApiV1SwapLightningClosePositionro  .contractPrivatePostApiV1LightningClosePositionrs  AcontractPrivatePostLinearSwapApiV1SwapCrossLightningClosePosition<contractPrivatePostLinearSwapApiV1SwapLightningClosePositionr  )
r5  re  r(  rR  rc  r  rp  r  rU  r  s
             r7  close_positionzhtx.close_position"  s#   ( 	V$$((AAj! 	aTW'__```$$_dFCCC#D\
 
 $)6G%&) 	I''(CCF~'  3E  )E  F  F  F $ 8 8 H HGH6#H#H#HII) 	{f~ mVVW[WbWbcjlrWsWsttNNt{{[bdjOkOkllJ!%!C!COU[]d!e!eJW$$aabfbmbmnuw}b~b~\\]a]h]hiprx]y]yzz&111r8  r  c                    |                                   |rdnd}d}||                     |          }d}|                     d|d          \  }}d|i}d}||d         rt          | j        dz             |d	k    rN|t          | j        d
z             |d         |d<   |                     |                     ||                    }n.d|d<   |                     |                     ||                    }|S )a  
        set hedged to True or False

        https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-switch-position-mode
        https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-switch-position-mode

        :param bool hedged: set to True to for hedged mode, must be set separately for each market in isolated margin mode, only valid for linear markets
        :param str [symbol]: unified market symbol, required for isolated margin mode
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: "cross"(default) or "isolated"
        :returns dict: response from the exchange
        	dual_sidesingle_sideNr   rl  position_moder   z4 setPositionMode can only be used for linear marketsrm  zD setPositionMode requires a symbol argument for isolated margin moder=   r  r&  )	rF  rc  rs  r+   r=   r*   8contractPrivatePostLinearSwapApiV1SwapSwitchPositionModero  =contractPrivatePostLinearSwapApiV1SwapCrossSwitchPositionMode)	r5  r  re  rR  posModerc  r  rp  rU  s	            r7  set_position_modezhtx.set_position_mode2#  s4    	!':++][[((F
!??@QSY[bcc
FW
 VI%6TW']]^^^##~'2x(xyyy(.tG$%TTUYU`U`ahjpUqUqrrHH )/G$%YYZ^ZeZefmouZvZvwwH r8  c                 D   |                                   |                     |dddd          }d}|@t          |          }|dk    r+|                     |d          }|                     |          }d}|                     d|d          \  }}d}|                     d||d          \  }}d}|                     d||          \  }}|dk    rd}d}	|dk    rO|d	k    r|                     |          }	n|dk    r| 	                    |          }	nft          | j        d
z             |dk    r|                     |          }	n3|dk    r|                     |          }	nt          | j        d
z             |                     |	dg           }
|                     |
|          S )a  
        fetches the auto deleveraging rank and risk percentage for a list of symbols

        https://www.htx.com/en-us/opend/newApiPages/?id=8cb81b5a-77b5-11ed-9966-0242ac110003
        https://www.htx.com/en-us/opend/newApiPages/?id=8cb81c49-77b5-11ed-9966-0242ac110003
        https://www.htx.com/en-us/opend/newApiPages/?id=28c2f164-77ae-11ed-9966-0242ac110003
        https://www.htx.com/en-us/opend/newApiPages/?id=5d518648-77b6-11ed-9966-0242ac110003

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `auto de leverage structures <https://docs.ccxt.com/?id=auto-de-leverage-structure>`
        NTr   r   rl  r   rM   rP   rm  z5 fetchPositionsADLRank() not support self market typerO   r]  )rF  r  ru  rI  rc  rs  r  rG  rE  rF  r0   r=   rG  rH  r  parse_adl_ranks)r5  rm  rR  rc  rJ  rq  r  r;  rS  rU  r]  s              r7  fetch_positions_adl_rankzhtx.fetch_positions_adl_rankn#  s    	%%gtT4FFLLMq  ((!44U++
!??@WY_ahii
F99:QSY[ackll
!??@WY_aghh
F!JhZ''RRSYZZw&&WWX^__"47-d#deeed X%%LLVTTb v%%LLVTT< #47-d#deee~~h33##D'222r8  c                     |                      |d          }||                     ||d d          |                     |d          d d d d dS )Nr  r   adl_risk_percent)rE  re  rankratingr   r  rY  )rI  rh  r  )r5  rE  rc  rj  s       r7  parse_adl_rankzhtx.parse_adl_rank$  sc    H ##D/::&&xzJJ%%d,>??
 
 	
r8  )N)NN)__name__
__module____qualname__r   r2  rZ  r   ra  dictr   r"   rk  r  rr  r   rz  rv  r   r}  r  r%   r  r  r  r   r  r  r   r  r%  r+  r   r7  r!   r[  r_  r^  rx  r  r  r  r  r   r  r  r  r
   r  r  r  r   r  r  r  r  r#  r%  r=  r?  r   rB  rD  rX  ri  r  rc  r  r   r   r   r  r  r  r  r   r  r  r  r  r  r  r   r$  r   r*  r1  r8  r#   rA  rC  rT  rR  r   r$   rq  r   r   r  r   r  r  r   r  r  r  r    r  r	   r  r  r1  r  intr  r  r  r!  rB  r   rK  rS  rZ  r   rf  rl  r   rp  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  boolr  r   r  r  __classcell__)r6  s   @r7  r:   r:       s       j# j j j j j jX+ #% [
 [
 [
 [
z !# ; ;s ; ; ; ;<
 
T 
6 
EX 
 
 
 
( 57 !5 !5 !5;N !5 !5 !5 !5F 7;2  G     :< P PS P P P P@ :>b 
 
3 
 
 
 
4x x x $&    $v,        D RT Z Zs ZS Z Z Z Zx  3            D] ]4 ] ]6 ] ] ] ]~ 02 N N3 Nf N N N N` 04B hH hHW hH7 hH hH hH hHT 48 c5 c5 c5 c5 c5 c5J
 
f 
 
 
 
  :>b Tr Trs Tr3 TrY Tr Tr Tr TrlI I Iv I I I I IV 9=4^bkm N NS N# NS NX[ N N N N, >BPTcgpr G G# Gs G# G]` G G G G* -1tRV_a Y? Y?c Y? Y?C Y? Y? Y? Y?v 6:UW HY HY3 HYs HY# HY\`af\g HY HY HY HYT
 
 
4 
 
 
 
, 9=4^bkm H H# H# HS HX[ Hrvw{r| H H H HB %' ) )4= ) ) ) ).
 
 
& EIX\eg #6 #6S #6c #6RU #6 #6 #6 #6J ') q qZ q q q qfA AC Ac A A A A A AQ Qc Q Q Q Q Q Q Q $& d d( d d d dL 26b H' H'c H'3 H' H' H' H'T
 
 
 AESWfjsu A= A=# A=S A=`c A= A= A= A=F /3TXac Y Y Y3 Yc Y Y Y Y 6:[_hj r rs r# rUX r r r r 37TX\eg [? [?C [?s [?RU [? [? [? [?z :>D_cln ^ ^3 ^c ^Y\ ^ ^ ^ ^ *.Dt\^ !H !H3 !Hc !H !Hcghmcn !H !H !H !HF 154VZce  S  S#  SS  SPS  Sjnotju  S  S  S  SD /3TXac ]? ]? ]?3 ]?c ]?hlmrhs ]? ]? ]? ]?~: : : : :*j j jv j j j j jX RT N N N5 N N N N$ x|  UY  w{  DF L LC Ly LPY Lch Lqt L  OR L  qt L  KP L L L L* tx  AC f, f, f,9 f,I f,_d f,mp f, f, f, f,P x|  EG V, V,C V,y V,PY V,ch V,qt V, V, V, V,p gksu `0 `03 `0i `0y `0RW `0`c `0 `0 `0 `0D @B r1 r1D$6 r1 r1 r1 r1h 37r y ys yC y y y yv ;?r R. R.c R.C R. R. R. R.h4 4 4l /32 s2 s2 s2 s2 s2 s2j <>  s    6
 
h 
 
 
 
4 DF 0 0s 0$~J^ 0 0 0 0B 79 5 5# 5^ 5 5 5 5" 8<VX  S    @ *.Dt\^ 6Q 6Q3 6Qc 6Q 6Qcghsct 6Q 6Q 6Q 6Qp -1tRV_a 4Q 4Qc 4Q 4QC 4Qfjkvfw 4Q 4Q 4Q 4QlZ
 Z
T Z
X Z
Q\ Z
 Z
 Z
 Z
x:s : : : :0 KOWY 6: 6:S 6:% 6:# 6:C 6:^i 6: 6: 6: 6:p
 
t 
x 
= 
 
 
 
. [] R7 R7S R7% R7c R7c R7an R7 R7 R7 R7h 24 )6 )68K )6 )6 )6 )6V)
 )
t )
V )
Oa )
 )
 )
 )
V 8<$]ajl LY LY LYC LYWZ LY LY LY LY\+
 +
6 +
[ +
 +
 +
 +
Z? ? ? 68 '7 '7 '7K '7 '7 '7 '7R 6:" 27 277 27 27 27 27 27h 15DW[jnwy ;Q ;Q# ;Qc ;QQT ;Qdg ;Q  C  DR  S ;Q ;Q ;Q ;Qz9
 9
$ 9
 9
. 9
 9
 9
 9
vD D D &eBSW lP lP lP lP\c 3 S # X\ dg    B 37TX\eg R> R>C R>s R>RU R> R> R> R>h 9=R G GS G# G G G GR
 
6 
 
 
 
8X Xt XV X X X Xt 26b FP FPw FPT(^ FP FP FP FPP 24 x xS x x x xt3 3 3&% %t %x %; % % % %N (,$TZ\ I? I? I?C I?s I?aefqar I? I? I? I?V 7;2 'I 'IG 'I- 'I 'I 'I 'IR  $|J\    0 BFTXgktv pM pM# pMc pMad pM pM pM pMd 7;2 [8 [8G [8 [8 [8 [8z 79 d d# d d d dLB BF B B B BH TV ! !S ! !U ! ! ! !F DF   U    @ LN & &C &s & & & &P <> $ $s $ $ $ $L
 
 
 
 
 
B 6:[_hj `6 `6s `6# `6UX `6 `6 `6 `6D <@ 1I 1I 1I 1I 1I 1If= = = = = =~5 5 5n 
  
  
D <@d[] =C =C =CS =C =C =C =C =C~ V    @ =A 32 32S 32	 32PU 32 32 32 32j =A : : :c : : : :x ;?r i3 i3 i3dSVi i3 i3 i3 i3VM
 M
4 M
 M
3 M
 M
 M
 M
 M
 M
 M
 M
r8  r:   )?ccxt.base.exchanger   ccxt.abstract.htxr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   typingr%   ccxt.base.errorsr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   ccxt.base.decimal_to_precisionr6   r7   ccxt.base.preciser8   r:    r8  r7  <module>r     s~   ( ' ' ' ' ' ) ) ) ) ) )  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E  E       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) , , , , , , . . . . . . 1 1 1 1 1 1 * * * * * * + + + + + + 3 3 3 3 3 3 4 4 4 4 4 4 % % % % % %FQ
 FQ
 FQ
 FQ
 FQ
(K FQ
 FQ
 FQ
 FQ
 FQ
r8  