
    !:h9                       d dl mZ d dlmZ d dl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% 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>y)    )Exchange)ImplicitAPIN)AccountAny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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/dd/ed0ef fd1Z0dd2ed0ef fd3Z1i fde2fd4Z3di fded	efd5Z4d6 Z5dddi fd	ed!edefd7Z6dddi fd	ed!edefd8Z7dddi fd	ed!edefd9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d@Z?ddAede	de;fdBZ@i fd	edCeAfdDZBdddi fd	edeCdEeDdFeAdGeEde;fdHZFdi fd	edeCdEeDdFeAdGeEf
dIZGdi fd	edeCdEeDdFeAdGeEf
dJZHdi fd	edeCdEeDdFeAdGeEf
dKZIi fdLeeJ   fdMZKdi fded	efdNZLdi fd	efdOZMdP ZNdi fd	efdQZOi fdRefdSZPddTeQfdUZRi fdVedeeS   fdWZTi fdVedeSfdXZUddi fdVefdYZVdddi fdVed!ededeeW   fdZZXdddi fdVed!ededeeW   fd[ZYdd\edTeQdeWfd]ZZd?efd^Z[di fdVedFeAd_edeWfd`Z\ddaedTeQde]fdbZ^i fdVedFeAdceddede]f
deZ_i fde`fdfZaddgede	debfdhZcdddi fd	ed!edefdiZddde	deefdjZfdk Zgi fd	edeefdlZhdi fdedeifdmZjddddi fdVed	ed!ededeek   f
dnZlddgede	dekfdoZmdp Zndqdri ddfdsZodtepduedvedwedxedyefdzZqdddi fd	ed!edefd{Zrdi fd|ed	efd}Zsdde	fd~Ztddede	fdZudi fdedeev   fdZwi fd	efdZxd ZyddedTeQdezfdZ{dddi fdVe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dVedFeAfdZi fdVedFeAfdZi fd	edVefdZi fdVefdZddTeQfdZdddi fd	ed!edefdZdi fdefdZddTeQfdZd Zd Zddi fd	ed!edefdZdde	fdZdi fd	edEeDde;fdZdi fded	efdZ xZS )htxreturnc                     | j                  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dedCdfd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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dddddddddddd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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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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d0dd1dd2dd3dd4di d5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDddEdi dFddGddHddIddJddKddLddMddNddOddPddQddRddSddTddUddVdi dWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfddgdddddddddddddddhdƜdFdidjdkdd!d| j                  dl      | j                  dl      dmidnt        t        t        doi dpt        dqt        drt        dst        dtt        dut        dvt        dwt        dxt        dyt        dzt        d{t        d|t        d}t        d~t        dt        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"        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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@dAdBdBdCdCdDdDdEdEdFdFdGdGi dHdHdIdIdJdJdKdKdLdLdMdNdOdOdPdPdQdQdRdRdSdSdTdTdUdUdVdVdWdWdXdXdYdYi dZdZd[d[d\d\d]d]d^d^d_d_d`d`dadadbdbdcdcdddedfdfdgdgdhdhdididjdjdkdkdldmdndodpdqddrdsdtdduidvdddwdxdydddz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      S (  Nidr9   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fetchPositionHistoryfetchPositions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.comzstatus.huobigroup.comzstatus-dm.huobigroup.comz!status-linear-swap.huobigroup.com)inverselinearzstatus-swap.huobigroup.com)rL   rO   rN   )contractrL   statuszhttps://{hostname})r   r   rL   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_price)z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!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_ratez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_hisorders)z,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_hisorders)r   r   r   r   r   rL   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-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-disabledzbase-symbol-errorzsystem-maintenancez#base-request-exceed-frequency-limitzinvalid symbol)z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)rL   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)rL   fundingrO   accountsByIdotcpointsuper-margin
investmentborrowgrid-tradingdeposit-earningotc-options)
rL   rM   r  r  r  r  r  r  r  r  )rI   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)typesByAccountrL   GFNGLTHEMISGAMECOMHITCHAINPENTASUPERBITCOIN	SOULSAVERBITCOINFILEzFTX Users Debt)	NGLGETGTCHITPNTrb  SOULrc  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   rp   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   rp   r   r$  forDerivatives)r   r   )rL   r%  rN   rO   )commonCurrenciesfeatures)deep_extendsuperr9   describe
userAgentsparse_numberr3   r'   r&   r(   r+   r.   r-   r,   r*   r4   r2   r1   r6   )self	__class__s    P/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/htx.pyr*  zhtx.describe#   sv3   c4 9 ; H>
%H>
EH>
 $H>
 	H>

 5H>
 H>
 tH>
 H>
 4H>
  ppp $p 	p
 $p $p Tp $Tp 'p "4p 'p tp p $Up  p  '!p" /#p$ ,U%p& 0'p( t)p* +p, (-p. '/p0 &t1p2 (3p4 "45p6 (7p8 -d9p: %d;p<  =p> ?p@  ApB &tCpD +DEpF )$GpH &tIpJ #DKpL $TMpN 'OpP (QpR "4SpT UpV &tWpX (YpZ 1$[p\  ]p^ *:_p` +Dapb &tcpd #Depf *4gph $Tipj "4kpl *5mpn +Dopp #Dqpr "4spt tupv #Dwpx  ypz %d{p| $T}p~ /p@ +JApB CpD !$EpF &uGpH  IpJ dKpL $TMpN +DOpP %dQpR !$SpT "4UpV dWpX !$YpZ "4[p\ t]p^ #D_p`  apb '
cpd !$epf (gph %eipj )$kpl )$mpn topp tqpr spt Tupv twpx "4ypz #E{p| %d}p~ &tp@ 'ApB $TCpD !$EpF )$GpH "4IpJ #DKpL +DMpN !%$('+#!&#'  _pH>
v wH>
N  ~ .+ 7'A&I#
 (D&I!
& 3 4023 4!5 /X $ ;]/OH>
n  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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@ ! 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 , :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 R 4558:=9:;<@A4545<=3423,-m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!, 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!R HI78/012:<35a1!sk =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 & 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 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 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 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 r MNIJKLLMJKJKDEJKOPJKTUUVFGRSMg iZ >?BC>?CDEFJKKLEFGHTULMTU "c!?c! ;Ac! <Q	c!
 7c! ?c! DQc! ?c! @c! ?c! Eac! Fqc! :1c! 21c! =ac!  =a!c!" DQ#c!$ B1%c!& I!'c!( CA)c!* ?+c!, Ea-c!0 ;A1c!2 4Q3c!4 9!5c!6 5a7c!8 89c!: @;c!< >q=c!> 9!?c!@ ;AAc!B 9!Cc!D 8Ec!F >qGc!H ;AIc!J A!Kc!L 8Mc!N >qOc!P ;AQc!R A!Sc!V <QWc!X =aYc!Z @[c!\ A!]c!^ @_c!` 9!ac!b :1cc!d =aec!f >qgc!h =aic!j B1kc!l :1mc!n ;Aoc!p >qqc!r ?sc!t >quc!x A!yc!z <Q{c!| =a}c!~ Eac!@ 8Ac!B @Cc!D EaEc!F @Gc!H A!Ic!J @Kc!L FqMc!N GOc!P DQQc!R ;ASc!T 3AUc!V >qWc!X >qYc!Z CA[c!\ J1]c!^ @_c!` Fqac!d <Qec!f 5agc!h :1ic!j 6qkc!l 9!mc!n Hoc!p A!qc!r :1sc!t <Quc!v :1wc!x 9!yc!z ?{c!| <Q}c!~ B1c!@ <QAc!B B1Cc!D 9!Ec!F ?Gc!J =aKc!L >qMc!N A!Oc!P B1Qc!R A!Sc!T :1Uc!V ;AWc!X >qYc!Z ?[c!\ >q]c!^ CA_c!` ;Aac!b <Qcc!d ?ec!f @gc!h ?ic!l KAmc!n QRSoc!p Hqc!r CAsc!t I!uc!v DQwc!x J1yc!z LQ{c!| RST}c!~ ?c!@ GAc!B MaCc!D LQEc!F RSTGc!H GIc!J MaKc!L HMc!N NqOc!P GQc!R MaSc!T NqUc!V TUVWc!X KAYc!Z QRS[c!\ B1]c!^ :1_c!` Eaac!b KAcc!d Eaec!f KAgc!h J1ic!j QRSkc!l Eamc!n Goc!p Maqc!t <Quc!v B1wc!x A!yc!z G{c!| =a}c!~ CAc!@ @Ac!B FqCc!D HEc!F NqGc!H OPQIc!J UVWKc!L A!Mc!N GOc!P CAQc!R I!Sc!T A!Uc!V GWc!X @Yc!Z Fq[c!\ Fq]c!^ LQ_c!` CAac!b I!cc!d I!ec!f OPQgc!h Eaic!j KAkc!l QRSmc!n CAoc!p I!qc!r I!sc!t OPQuc!v @wc!x Fqyc!z Fq{c!| LQ}c!~ LQc!@ J1Ac!B HCc!F DQGc!H J1Ic!J EaKc!L KAMc!N HOc!P NqQc!R I!Sc!T OPQUc!V HWc!X NqYc!Z A![c!\ G]c!^ B1_c!` Hac!b Eacc!d KAec!f Fqgc!h LQic!j Eakc!l MNKLQRCDIJDEJKGHMNHINOGHMNEc!%v Wbm	Y
oH>
b $!&"&!..w7!..w7cH>
t ly -1A
>.> -> /	>
 I> M> L> L> L> L> -> -> M> L> I>  L!>" L#>$ -%>& J'>( L)>* J+>, ":->. .z/>0 6z1>2 ,Z3>4 01A5>6 ~7>8 -.B9>: @AR;>< %l=>> 8?>@ 8A>B 9,C>D 7E>F 7G>H 3LI>J ,\K>L *<M>N 1,O>P 7Q>R 4\S>T -mU>V /W>X )*>Y>Z 12E[>\ ./B]>^ *=_>` 1)a>b (c>d )-e>f :;Lg>j %ik>l 2;&/'11;/@/9-7%6{>EuH>
@ YAH>
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CH>
r%  !
 &#%'!!(  $&*(,,0,0).+06:#'#'"&#(	( #($)#(/3$(+/26)$. r% ',!$$'%&*/& ',#($)*/	# ',#'$)!$*/( ',#'$)!$%&$'*/$ ',#'$)%&!$$',2*/	*  #EEN  &)-+/$("&	$ r% %d# '+#($)!#	( '+#($)!#$&$ '+#($)%&!#$&,2*  #K(#V "#3 "#3 	 "#3 "#3 	q@O&H>
 H H	    c                   K   | j                          d{    d}| j                  dd|      \  }}| j                  ddd      }d}|dk7  r|r| j                  |d| j                  d         }|dk(  r<|d	k(  r| j                          d{   }n|d
k(  r| j                          d{   }n||dk(  r<|d	k(  r| j                          d{   }nY|d
k(  rT| j                          d{   }n;|dk(  r6| j                          d{   }n|dk(  r| j                          d{   }d}d}d}|dk(  r3| j                  |d      }	|	d}n	|	dk(  rdnd}| j                  |d      }nv| j                  |di       }
| j                  |
d      }	|	dk(  rdnd}| j                  |di       }| j                  |d      }| j                  |      }| j                  |d      }||d||dS 7 7 _7 D7 $7 	7 7 ѭw)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   enableForContractsFrL   subTyper  rN   r   r   rO   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)r-  params
marketTypeenabledForContractsresponser3  r   r;  r   	statusRaw
statusDatapageDatadatetimes                r/  fetch_statuszhtx.fetch_statusn  s.     !!!
!??tU[\
F"00@TV[\$7&&vy$,,GW:XYGV#h&%)%S%S%UUH	)%)%T%T%VVHx'h&%)%U%U%WWH	)%)%V%V%XXHz)!%!@!@!BB6!!EEGGHD #((8<I "+t"3-&&x6G8R@J(([AI'61TFx<H'',?HnnX.G""8U3C
 	
Q 	"  VV  XXBGs}   G;G(A5G;G+G;*G.+"G;G1G;+G4,G;	G7
G;'G9(CG;+G;.G;1G;4G;7G;9G;c                 v  K   | j                  | j                  di       }| j                  | j                  dd      }| j                  |d|      }| j                  |d|      }d}|dk(  s|dk(  r| j                  |       d{   }n| j	                  |       d{   }| j                  |dd	      S 7 17 w)
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  rL   typeNrO   rN   datar6  )rH  r  rA  contractPublicGetApiV1TimestampspotPublicGetV1CommonTimestampsafe_integer_2)r-  rJ  r  r  rT  rM  s         r/  
fetch_timezhtx.fetch_timeK  s      //$,,R@&&t||]FK=5H$&.!AA&IIH!@@HHH ""8VT:: JHs$   BB9B5B9B7B97B9Nfeemarketc                     | j                  |d      }|| j                  ||      | j                  |d      | j                  |d      d d dS )NsymbolactualMakerRateactualTakerRate)r=  r]  r   r   r   r   )rA  safe_symbolsafe_number)r-  rZ  r[  marketIds       r/  parse_trading_feezhtx.parse_trading_feei  s[     ##C2&&x8%%c+<=%%c+<=
 	
r0  r]  c                 4  K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |dg       }| j	                  |di       }| j                  ||      S 7 }7 >w)ao  
        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>`
        Nsymbolsr<   rU  r   )r>  r[  (spotPrivateGetV2ReferenceTransactFeeRateextendrH  rc  )r-  r]  rJ  r[  requestrM  rU  firsts           r/  fetch_trading_feezhtx.fetch_trading_fee}  s      !!!V$vd|
 FFt{{SZ\bGcdd  x4a,%%eV44/ 	"
 es"   BBA BB=BBre  c                    K   | j                          d {    || j                  }i }t        dt        |            D ]3  }||   }| j	                  | j                  |      |       d {   ||<   5 |S 7 a7 w)Nr   )r>  re  rangelenfetch_trading_limits_by_id	market_id)r-  re  rJ  resultir]  s         r/  fetch_trading_limitszhtx.fetch_trading_limits  s      !!!?llGq#g,' 	cAQZF#'#B#B4>>RXCY[a#bbF6N	c  	" cs"   A<A8AA<,A:-A<:A<r<   c                    K   d|i}| j                  | j                  ||             d{   }| j                  | j                  |di             S 7 &w)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
        r]  NrU  )spotPublicGetV1CommonExchangerg  parse_trading_limitsrH  )r-  r<   rJ  rh  rM  s        r/  rn  zhtx.fetch_trading_limits_by_id  s[      b
 ;;DKKQW<XYY" ((62)NOO# Zs   )AA'Ac                 V    |d| j                  |d      | j                  |d      didS )Namountzlimit-order-must-greater-thanzlimit-order-must-less-thanminr  )r=  limits)ra  )r-  rz  r]  rJ  s       r/  ru  zhtx.parse_trading_limits  s@    " ++F4ST++F4PQ
 	
r0  c                 l    | j                  |t        | j                  |   d   d   | j                        S )N	precisioncost)decimal_to_precisionr5   marketsr  )r-  r]  r}  s      r/  cost_to_precisionzhtx.cost_to_precision  s4    ((xf9Mk9Z[a9bdhdvdvwwr0  c                   K   | j                   d   r| j                          d{    d}| j                  |ddi       \  }}g }g }t        |j	                               }t        dt        |            D ]  }||   }| j                  ||      s|dk(  r#|j                  | j                  dd|             C|dk(  r#|j                  | j                  dd|             k|dk(  sq|j                  | j                  d	d|             |j                  | j                  d
d|              t        j                  |  d{   }t        dt        |            D ]  }| j                  |||         } |S 7 R7 8w)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   rL   r   r   rN   rO   )r  load_time_differencehandle_option_and_paramslistkeysrl  rm  	safe_boolappend"fetch_markets_by_type_and_sub_typeasynciogatherarray_concat)r-  rJ  r  
allMarketspromisesr  rq  keys           r/  fetch_marketszhtx.fetch_markets  st     <<12++---55fngWYZv
EJJL!q#d)$ 		jAq'C~~eS)&=OOD$K$KFTXZ`$abH_OOD$K$KDRZ\b$cdI%OOD$K$KFT]_e$fgOOD$K$KHV_ag$hi		j !22q#h-( 	DA**:x{CJ	D' .  3s0   #E<E7A)E<AE<&AE<E:6E<:E<rT  r3  c                   K   |dk(  }i }d}|s|dk(  r/d|d<   | j                  | j                  ||             d{   }n|dk(  r|dk(  r*| j                  | j                  ||             d{   }nX|dk(  rS| j                  | j                  ||             d{   }n)| j	                  | j                  ||             d{   }| j                  |d	g       }t        |      }|d
k  r*t        | j                  dz   | j                  |      z         g }	t        dt        |            D ]  }
||
   }d}d}d}d}d}d|v }| }d}d}d}d}|r| j                  |d      }|j                         }| j                  |d      }| j                  |d      }|du}| }|du}| }|r>d}|j                  d      }| j                  |d      }| j                  |d
      }|r|n|}n|rd}| j                  |d      }|rd}|}ns| j                  |d      }|j                  d      }| j                  |d
      }|}n;d}| j                  |d      }| j                  |d      }||z   }|j                         }| j                  |      }| j                  |      }| j                  |      }|dz   |z   }d}|r@|r	|d|z   z  }n
|r|d|z   z  }|r)| j!                  |d      }|d| j#                  |      z   z  }| j%                  |d      } | j%                  |d      }!| j%                  |d      }"| j%                  |d      }#|r	|r| }#n|r| }!d}$d}%d}&d}'d}(d})|r| j'                  | j)                  | j                  |d                  }$| j'                  | j)                  | j                  |d                  }%| j'                  | j)                  | j                  |d                  }&| j'                  d       }'| j'                  d       }(| j                  |d!      }*|*d"k(  })n\| j%                  |d#      }$| j'                  d$      }%| j'                  d%      }'| j'                  d&      }(| j!                  |d'      }+|+d
k(  })| j                  |d(d$      },| j                  |d)d$      }-t+        j,                  |,d$      xs t+        j,                  |-d$      }.d}/| j                  |d*      }0|0Z| j/                  |0      }1|1d   |1d
   z   |1d+   z   |1d,   z   dz   |1d-   z   |1d.   z   dz   |1d/   z   |1d0   z   d1z   }0| j1                  |0      }/|	j3                  i d2|d3|d|d4|d5|d6|d7|d8|d9|d:|d|d;|xr |.d|d|d<dd=|)d>||||(|'| || j5                  |      dd|%|$|&d?| j'                  d$      | j'                  |,      | j'                  |-      d@|#|"dAdddA|!ddAdB|/|dC        |	S 7 7 7 Z7 3w)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
        rL   Nr   allbusiness_typer   rO   rN   rU  r   z, fetchMarkets() returned an empty response: r   contract_codeFdelivery_date-r]  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settleIdrT  rM   rP   activer   )rw  pricer}  )ry  r  superMaxrx  )r  rw  r  r}  )r   r   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper|  rz  createdr=  )0contractPublicGetLinearSwapApiV1SwapContractInforg  *contractPublicGetApiV1ContractContractInfo*contractPublicGetSwapApiV1SwapContractInfospotPublicGetV1CommonSymbols	safe_listrm  r0   r<   jsonrl  rA  lowersplitsafe_string_lowersafe_currency_codesafe_integeryymmddra  r,  parse_precisionr7   	string_gtstring_to_chars_arrayrI  r  iso8601)2r-  rT  r3  rJ  isSpotrh  rM  r  
numMarketsrp  rq  r[  r  r  r  r<   r  r   rL   rN   rO   r   r   r  r  partsr  r  r  r  r]  r  r  minCost	maxAmount	minAmountpricePrecisionamountPrecisioncostPrecisionr   r   r  r  contractStatusleverageRatiosuperLeverageRatiohasLeverager  createdDatecreatedArrays2                                                     r/  r  z&htx.fetch_markets_by_type_and_sub_type  s     &.("+0(!%!V!VW[WbWbcjlrWs!ttI%8#%)%T%TUYU`U`ahjpUq%rrHV^%)%T%TUYU`U`ahjpUq%rrH!>>t{{7TZ?[\\Hn ..626\
>!$'',Z"Z]a]f]fgo]p"pqqq#g,' a	AQZFFGHBK'61H<DDFFG%%fo> hhj $ 0 0 I $ 0 0 I&d2!z&d2$*!DHHSME!33FHEF"44UA>G)0vgH#D!33FHEF"'#)#//? $

3"&"8"8"B#*))&/B**63CDg% hhj**62D++G4E,,X6FCZ%'FFcDj(FcEk)F!..vGFcDKK$777F++FODL&&v/@AG((AI((AI ,I*G!N"O MEEF!%!2!243G3GHXHXY_arHs3t!u"&"3"3D4H4HIYIYZ`btIu4v"w $ 1 1$2F2FtGWGWX^`qGr2s t))'2))'2((98+!%!1!1&,!G"&"3"3C"8))(3))(3!%!2!26;L!M(A- ,,V5EsKM!%!1!1&:WY\!]!++M3?m7CTCTUgilCmK G**6=AK&#99+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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"-+)  $005#00?$($5$56H$I!  )(
  $#
  '#& #i5 5Ya	D K u  sr\sF   :W?W33W?0W61.W?W9 )W?	W<
T*W?6W?9W?<W?symbolOrMarketIdc                 2   || j                   v r|S d| j                  vri | j                  d<   | j                  | j                  di       }||v r||   S | j                  | j                   dd      }ddddd}t	        d	t        |            D ]u  }||   }| j                  |d
i       }| j                  |d      }||   }	|d   r|d   dz   |d   z   dz   |	z   n
|d   dz   |	z   }
|
|k(  s\|d   }|| j                  d   |<   |c S  || j                  d   |<   |S )NfutureMarketIdsForSymbolsrO   TCWNWCQNQ)	this_week	next_weekquarternext_quarterr   r=  contract_typer   r  r  r  _r]  )r  r  	safe_dict	filter_byrl  rm  rH  rA  )r-  r  r  futureMarketsfuturesCharsMapsrq  r[  r=  contractTypecontractSuffixconstructedIdr]  s               r/  "try_get_symbol_from_future_marketsz&htx.try_get_symbol_from_future_markets(  s   t||+##
 ,t||;8:DLL45$(NN4<<A\^`$a!88,-=>>t||XtD 	"
 q#m,- 
	A"1%F??6626D++D/BL-l;N]cdl]mF6NS06'?BSH>Ysy  {A  tB  EH  tH  KY  tYM 00)NT89:JK
	 GW012BCr0  tickerc                    | j                  |dd      }| j                  ||      }| j                  |      }| j                  |dd      }d }d }d }d }	d|v rg|d   >t	        |d   t
              r+| j                  |d   d      }| j                  |d   d      }n$| j                  |d      }| j                  |d      }d	|v rg|d	   >t	        |d	   t
              r+| j                  |d	   d      }| j                  |d	   d      }	n$| j                  |d	      }| j                  |d
      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d      }| j                  i d|d|d| j                  |      d| j                  |d      d| j                  |d      d|d|d	|d|	dd d|
d|d|dd dd dd dd |||d|      S )Nr]  r  r6  	quoteTimebidr   r   bidSizeaskaskSizeopencloserw  vol	timestamprQ  highlow	bidVolume	askVolumevwaplastpreviousClosechanger   average)
baseVolumequoteVolumer=  )	safe_string_2r`  r  rX  
isinstancer  rA  safe_tickerr  )r-  r  r[  rb  r]  r  r  r  r  r  r  r  r  r  s                 r/  parse_tickerzhtx.parse_tickerJ  s   \ %%fhH!!(F388@''kB			F?e}(Zut-L&&ve}a8 ,,VE]A>	&&vu5 ,,VY?	F?e}(Zut-L&&ve}a8 ,,VE]A>	&&vu5 ,,VY?	/  1%%fh7
&&vu5 !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 3!
 !
 3!
 !
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	r0  c                   K   | j                          d{    | j                  |      }i }d}|d   r2|d   |d<   | j                  | j                  ||             d{   }n|d   rn|d   r2|d   |d<   | j	                  | j                  ||             d{   }nh|d   rc|d   |d<   | j                  | j                  ||             d{   }n1|d   |d<   | j                  | j                  ||             d{   }| j                  |d	i       }| j                  ||      }| j                  |d
      }||d<   | j                  |      |d<   |S 7 G7 7 7 7 _w)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   rO   r]  rN   tickr6  r  rQ  )r>  r[  /contractPublicGetLinearSwapExMarketDetailMergedrg  #contractPublicGetMarketDetailMerged)contractPublicGetSwapExMarketDetailMergedspotPublicGetMarketDetailMergedrH  r  r  r  )	r-  r]  rJ  r[  rh  rM  r  r  r  s	            r/  fetch_tickerzhtx.fetch_ticker  s     !!!V$('-d|GO$!QQRVR]R]^egmRnooHIh$*4L!!%!I!I$++V]_eJf!gg+1$<(!%!O!OPTP[P[\cekPl!mm &tGH!AA$++gW]B^__HX x4""40%%h5	'{!\\)4zC 	" p h n `sY   E(EA
E(!E ";E(E"6E(E$1E(E&AE( E("E($E(&E(c                   K   | j                          d{    | j                  |      }| j                  |d      }d}|| j                  |      }d|v xs d|v }d}d}| j	                  d||      \  }}| j                  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<   | j                  | j                  ||             d{   }n|rp|
r*| j                  | j                  ||             d{   }n|r*| j                  | j                  ||             d{   }nYt        | j                  dz         t        | j                  dz         | j                  | j                  ||             d{   }| j                  |ddg       }| j                  |||      }| j                  |d|      S 7 7 7 7 7 Gw)aI  
        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>`
        Nr   r3  r  r   rL   rO   rN   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 contractsrU  ticksr]  )r>  market_symbolsrA  r[  r?  handle_sub_type_and_params4contractPublicGetLinearSwapExMarketDetailBatchMergedrg  (contractPublicGetMarketDetailBatchMerged.contractPublicGetSwapExMarketDetailBatchMergedr/   r<   spotPublicGetMarketTickerssafe_list_2parse_tickersfilter_by_array_tickers)r-  re  rJ  ri  r[  isSubTypeRequestedrT  r3  rh  r  rO   rN   r   r   rM  
rawTickerstickerss                    r/  fetch_tickerszhtx.fetch_tickers  sA     !!!%%g.  !,[['F'61Q&7P99.&RXYf99.&RXY&.("X%i'+/8GO,/5GO,/4GO,!%!Z!Z[_[f[fgnpv[w!xx%)%R%RSWS^S^_fhnSo%ppH%)%X%XY]YdYdelntYu%vvH&tww  2U  (U  V  V"477  .O  $O  P  P!<<T[[RX=YZZHf %%hD
$$Z&A++GXwGGw 	"6 y  qv [sY   G'GCG')G*-G'G!+G'G#AG'G%?G'G'!G'#G'%G'c                   K   | j                          d{    | j                  |      }| j                  |      }d}d}| j                  d||      \  }}| j	                  d||      \  }}d}|dk(  s|dk(  r|dk(  r| j                  |       d{   }nf|dk(  r|dk(  r| j                  |       d{   }nB|dk(  r|dk(  r| j                  |       d{   }nt        | j                  dz   |z   dz         | j                  |d	i       }| j                  |d
g       }| j                  ||      S 7  7 7 7 bw)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   rN   rO   r   r   z$ fetchLastPrices() does not support z markets yetr  rU  )r>  r  get_market_from_symbolsr  r?  (contractPublicGetLinearSwapExMarketTrade"contractPublicGetSwapExMarketTradecontractPublicGetMarketTrader/   r<   rH  r  parse_last_prices)	r-  re  rJ  r[  rT  r3  rM  r  rU  s	            r/  fetch_last_priceszhtx.fetch_last_pricesc	  sa     !!!%%g.--g699:KVU[\99:KVU[\fV^!1H9L!JJ6RRH4 fn7i#7!DDVLLH. hW	%9!>>vFFH0 tww)OORVVYgghhx4~~dFB/%%dG44o 	" S6 M0 GsG   D?D6A;D?D9#D?6D;7#D?D=AD?9D?;D?=D?c                     | j                  |dd      }| j                  ||      }| j                  |d      }| j                  |d      }|d   d d |||dS )Nr]  r  r  	direction)r]  r  rQ  r  sider=  )r  safe_marketra  rA  )r-  entryr[  rb  r  r!  s         r/  parse_last_pricezhtx.parse_last_price	  so    %%eXG!!(F3  0$$UK8	 X&
 	
r0  r  c                 "  K   | j                          d{    | j                  |      }ddi}d}|d   r2|d   |d<   | j                  | j                  ||             d{   }n|d   rn|d   r2|d   |d	<   | j	                  | j                  ||             d{   }n|d
   r|d   |d<   | j                  | j                  ||             d{   }ni|6|dk7  r'|dk7  r"|dk7  r|dk7  rt        | j                  dz         |dk7  r||d<   |d   |d	<   | j                  | j                  ||             d{   }d|v r|d   s*t        | j                  dz   | j                  |      z         | j                  |d      }| j                  |d| j                  |d            }| j                  |||      }	| j                  |d      |	d<   |	S t        | j                  dz   | j                  |      z         7 7 7 h7 47 ̭w)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
        NrT  step0r   r<   r  r   rO   r]  rN   r   r         zP fetchOrderBook() limit argument must be None, 5, 10, 20, or 150, default is 150depthr  z+ fetchOrderBook() returned empty response: r6  rF   noncez2 fetchOrderBook() returned unrecognized response: )r>  r[  (contractPublicGetLinearSwapExMarketDepthrg  contractPublicGetMarketDepth"contractPublicGetSwapExMarketDepthr*   r<   spotPublicGetMarketDepthr+   r  rH  r  parse_order_bookr%   )
r-  r]  r  rJ  r[  rh  rM  r  r  rp  s
             r/  fetch_order_bookzhtx.fetch_order_book	  sI     !!!V$ G

 ('-d|GO$!JJ4;;W^`fKghhHIh$*4L!!%!B!B4;;wX^C_!``+1$<(!%!H!HU\^dIe!ff QJUb[u{RU$TWW  0B  &B  C  C C<',GG$ &tGH!::4;;wPV;WXXH6 XF#*W WZ^ZcZcdlZm mnn??8V4D))$d6G6GRV6WXI**4CF"//i@F7OMDGG&ZZ]a]f]fgo]ppqqM 	"  i a g YsZ   HHAH#H$;HH 6HH
A)H HCHHH
HHtradec                    | j                  |dd      }| j                  ||      }|d   }| j                  |dd      }| j                  |dd|      }| j                  |dd      }| j                  |d	      }| j                  |d
      }||j	                  d      }	|	d   }|	d   }| j                  |d      }
| j                  |dd      }| j                  |dd      }| j                  |d|      }| j                  |d      }d }| j                  |d      }|%t        j                  | j                  |d            }| j                  |dd      }| j                  |      }| j                  |d      }|?|t        j                  |d      r'| j                  |d      }||}| j                  |      }|||d}| j                  |g d      }| j                  ||||| j                  |      ||||
||||d|      S )Nr  r]  r6  
created-at
created_atr  order-idorder_idr!  rT  r  r   r   roler  trade_pricefilled-amountrw  trade_volumetrade_turnoverfilled-fees	trade_feezfee-currency	fee_assetzfilled-points0zfee-deduct-currencyr}  currency)trade_idztrade-idr<   )r<   r=  orderr  rQ  r]  rT  r"  takerOrMakerr  rw  r}  rZ  )r  r#  rX  rA  r  r  r7   
string_negr  string_equalssafe_string_n
safe_trader  )r-  r2  r[  rb  r]  r  rD  r"  rT  	typePartsrE  priceStringamountString
costStringrZ  feeCostfeeCurrencyIdfeeCurrencyfilledPointsfeeDeductCurrencyr<   s                        r/  parse_tradezhtx.parse_trade.
  sI   ^ %%e_hG!!(F3!''t\B	''|]IV	""5*jA{3v.

3IQ<DQ<D--eV<((G))%(K''~|L%%e-=>
""5-8?(()9)9%)MNG**5.+N--m<''?#G$9$9'3$G$($4$4U<Q$R!$0*G"&"9"9:K"LK'C 'EF"Y/( " 
  	r0  sincec                    K   d}|| j                  |      }d}| j                  d||      \  }}|dk7  rt        | j                  dz         | j	                  |||||       d{   S 7 w)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   rL   z6 fetchOrderTrades() is only supported for spot markets)r[  r?  r/   r<   fetch_spot_order_trades)r-  r<   r]  rT  r  rJ  r[  rK  s           r/  fetch_order_tradeszhtx.fetch_order_trades
  s~      [[(F
!??@RTZ\bc
Ftww)aabb11"feUFSSSSs   A#A,%A*&A,c                    K   | j                          d{    d|i}| j                  | j                  ||             d{   }| j                  |d   d||      S 7 H7 w)a6  
 @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>`
        Nr6  rU  )r>  .spotPrivateGetV1OrderOrdersOrderIdMatchresultsrg  parse_trades)r-  r<   r]  rT  r  rJ  rh  rM  s           r/  rV  zhtx.fetch_spot_order_trades
  sp      !!!
 LLT[[Y`bhMijj  &!14FF 	" ks!   A#A,A#A!A#!A#c                 D  K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||       d{   S d}|| j                  |      }d}| j	                  d||      \  }}i }d}	|dk(  rj|| j                  |      }|d   |d<   |||d<   |||d	<   | j                  d
||      \  }}| j                  | j                  ||             d{   }	nT|t        | j                  dz         |d   |d<   d|d<   |||d<   | j                  d||      \  }}|||d<   |d   r{d}
| j                  d|      \  }
}|
dn|
}
|
dk(  r*| j                  | j                  ||             d{   }	n|
dk(  r| j                  | j                  ||             d{   }	n|d   r|dk(  r2|d   |d<   | j                  | j                  ||             d{   }	nM|dk(  r*| j                  | j                  ||             d{   }	nt        | j                  dz   |z   dz         | j!                  |	d      }t#        |t$              s| j!                  |d      }| j'                  ||||      S 7 x7 D7 7 7 7 7 {w)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>`
        NFr   paginaterL   r<   r]  size
start-timeend-timez+ fetchMyTrades() requires a symbol argumentr   r   
trade_type
start_timeend_time	page_sizer   crossisolatedr   rO   r  rN   z" fetchMyTrades() does not support  marketsrU  trades)r>  r  fetch_paginated_call_dynamicr[  r?  handle_until_option!spotPrivateGetV1OrderMatchresultsrg  r)   r<   handle_margin_mode_and_params7contractPrivatePostLinearSwapApiV3SwapMatchresultsExact<contractPrivatePostLinearSwapApiV3SwapCrossMatchresultsExact1contractPrivatePostApiV3ContractMatchresultsExact1contractPrivatePostSwapApiV3SwapMatchresultsExactr/   rH  r   r  rZ  )r-  r]  rT  r  rJ  r\  r[  rK  rh  rM  r  rg  s               r/  fetch_my_tradeszhtx.fetch_my_trades
  s"      !!!88R\]&::?FTY[`bhiii[[(F
!??QWY_`
F
& !V,$*4L! "' (-%"66z7FSOGV!CCDKKPWY_D`aaH~'2_(_``"(,GJ$%GL! (-%"66z7FSOGV ',$h!
%)%G%GY_%`"
F)3);W*
+%)%a%abfbmbmnuw}b~%H7*%)%f%fgkgrgrsz  }C  hD  &E   EH	")(.z(:GH%%)%[%[\`\g\ghoqw\x%yyH6)%)%[%[\`\g\ghoqw\x%yyH&tww1U'UXb'beo'oppF 62&$'__VX6F  >>S 	" jH b"  @  E  zys~   J J6J JBJ +J,BJ J	.J 7J8;J 3J4.J "J#A,J J J J J J J r  c                    K   | j                          d{    | j                  |      }i }|t        |d      |d<   d}|d   rn|d   r2|d   |d<   | j                  | j	                  ||             d{   }n|d   r|d   |d	<   | j                  | j	                  ||             d{   }n|d
   rf|d   |d	<   |d   r*| j                  | j	                  ||             d{   }n`|d   r[| j                  | j	                  ||             d{   }n1|d   |d<   | j                  | j	                  ||             d{   }| j                  |dg       }g }	t        dt        |            D ]X  }
| j                  ||
   dg       }t        dt        |            D ](  }| j                  ||   |      }|	j                  |       * Z | j                  |	d      }	| j                  |	|d   ||      S 7 7 7 V7 7 7 w)aj  

        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#  r]  rO   r   r<   r]  r   r  rN   rU  r   r  )r>  r[  ry  #contractPublicGetMarketHistoryTraderg  /contractPublicGetLinearSwapExMarketHistoryTrade)contractPublicGetSwapExMarketHistoryTradespotPublicGetMarketHistoryTraderH  rl  rm  rS  r  sort_byfilter_by_symbol_since_limit)r-  r]  rT  r  rJ  r[  rh  rM  rU  rp  rq  rg  jr2  s                 r/  fetch_tradeszhtx.fetch_tradesw  s5     !!!V$
 !%.GFO(i $*4L!!%!I!I$++V]_eJf!gg!+1$<(!%!U!UVZVaVabikqVr!ssF^'-d|GO$i !%!O!OPTP[P[\cekPl!mm!!%!U!UVZVaVabikqVr!ss &tGH!AA$++gW]B^__H2 x4q#d)$ 	%A__T!Wfb9F1c&k* %((F;e$%	%
 fk2009I5RWXXs 	" h t ns `sk   HG>A H7H86H.H/;H*H+.HH
1HHB3HHHH
HHc           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr<   r  r  r  r  rw  )safe_timestampra  )r-  ohlcvr[  s      r/  parse_ohlcvzhtx.parse_ohlcv  sn     t,UF+UF+UE*UG,UH-
 	
r0  r   c           	        K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d|||||d       d{   S | j                  |      }d| j	                  | j
                  ||      i}| j                  |ddg      }	| j                  |ddg      }d}
| j                  |d	      \  }
}|
| j                  |
dz        nd}|d
   r|t        |d      |d<   nd}|	p| j                  |      }d}|!| j                         }|||dz
  z  z
  |d<   |}n1| j                  |dz        }||d<   | j                  |||dz
  z        }||n||d<   d}|d   r|d   r|d   |d<   |	dk(  r+| j                  | j                  ||             d{   }n|	dk(  r+| j!                  | j                  ||             d{   }nY|	dk(  r't#        | j$                  dz   |d   z   dz   |	z   dz         | j'                  | j                  ||             d{   }n|d   r|d   |d<   |	dk(  r+| j)                  | j                  ||             d{   }n|	dk(  r't#        | j$                  dz   |d   z   dz   |	z   dz         |	dk(  r+| j+                  | j                  ||             d{   }nh| j-                  | j                  ||             d{   }n=|d   r|d   |d<   |d   r|	dk(  r+| j/                  | j                  ||             d{   }n|	dk(  r't#        | j$                  dz   |d   z   dz   |	z   dz         |	dk(  r+| j1                  | j                  ||             d{   }n| j3                  | j                  ||             d{   }ns|d   rm|	dk(  r+| j)                  | j                  ||             d{   }n=|	dk(  r't#        | j$                  dz   |d   z   dz   |	z   dz         |	dk(  r*| j+                  | j                  ||             d{   }n| j-                  | j                  ||             d{   }n|d   |d<   d}| j                  |ddd      \  }}|s;|t        |d      |d<   | j5                  | j                  ||             d{   }nZ|| j                  |dz        |d<   |||d<   |t        d|      |d<   | j7                  | j                  ||             d{   }| j9                  |d g       }| j;                  |||||      S 7 F7 7 7 7 =7 7 7 7 A7 7 7 7 47 7 7 Xw)!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
        NFr   r\  r  period	priceTyper  untilr   r#  r]  r   fromtorO   r   r<   r]  markindexpremiumIndex rT  z has no api endpoint for z kline datar   r  rN   r  TrU  )r>  r  "fetch_paginated_call_deterministicr[  rA  r   rH  omithandle_param_integerparse_to_intry  parse_timeframesecondssum1contractPublicGetIndexMarketHistoryMarkPriceKlinerg  (contractPublicGetIndexMarketHistoryIndexr*   r<   #contractPublicGetMarketHistoryKline;contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline>contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline/contractPublicGetLinearSwapExMarketHistoryKline5contractPublicGetIndexMarketHistorySwapMarkPriceKline8contractPublicGetIndexMarketHistorySwapPremiumIndexKline)contractPublicGetSwapExMarketHistoryKlinespotPublicGetMarketHistoryKline!spotPublicGetMarketHistoryCandlesr  parse_ohlcvs)r-  r]  	timeframerT  r  rJ  r\  r[  rh  r  r  untilSecondsdurationcalcualtedEndnowstartrM  useHistoricalrU  s                      r/  fetch_ohlcvzhtx.fetch_ohlcv  sY    $ !!!88zZ&@@vW\^cenpvx|}}}V$d&&t	9M
 &&vW/EF	6K#9:11&'Bv;@;Lt((6SW* "%eT"2  //	: $=,,.C&)H	,B&BGFO$'M --edl;E&+GFO$(HHUH	4J$KM1=1IP](i $*4L!&%)%[%[\`\g\ghoqw\x%yyH')%)%R%RSWS^S^_fhnSo%ppH.0$TWWs]VF^%CFa%adm%mp}%}~~%)%M%MdkkZaciNj%kkH!+1$<(&%)%e%efjfqfqry  |B  gC  &D   DH')$TWWs]VF^%CFa%adm%mp}%}~~.0%)%h%himititu|  E  jF  &G   GH%)%Y%YZ^ZeZefmouZv%wwHF^'-d|GO$i &%)%_%_`d`k`klsu{`|%}}H')$TWWs]VF^%CFa%adm%mp}%}~~.0%)%b%bcgcncnovx~c  &A   AH%)%S%STXT_T_`gioTp%qqH!&%)%e%efjfqfqry  |B  gC  &D   DH')$TWWs]VF^%CFa%adm%mp}%}~~.0%)%h%himititu|  E  jF  &G   GH%)%Y%YZ^ZeZefmouZv%wwH &tGH M$($A$A&,Xvx|$}!M6 $&)%&6GFO!%!E!EdkkRY[aFb!cc $&*&7&7&EGFO+$0GDM$&)$&6GFO!%!G!GT[]cHd!ee ~~h3  vy%GG[ 	" ~L  zp  l  D  Gw
  ~  Aq  D  Gw d fs%  V
U8V
UEV
$U"%/V
U%AV
+U(,=V
)U+*AV
U.*V
0U11AV
3U44AV
U7*V
:U:;5V
0U=1AV
V )V
6V7AV
VAV
/V0-V
V
"V
%V
(V
+V
.V
1V
4V
7V
:V
=V
 V
V
V
V
c                    K   | j                          d{    | j                  |       d{   }| j                  |d      }| j                  |      S 7 @7 )w)az  
        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
        NrU  )r>  spotPrivateGetV1AccountAccountsrH  parse_accountsr-  rJ  rM  rU  s       r/  fetch_accountszhtx.fetch_accountsX  sY      !!!==fEE x0""4(( 	"Es   AAAA(AAc                     | j                  |d      }| j                  | j                  di       }| j                  |||      }|| j                  |d      |d dS )NrT  r  r<   )r=  r<   rT  code)rA  rH  r  )r-  accounttypeIdr  rT  s        r/  parse_accountzhtx.parse_accounto  sa     !!'62t||^RH|VV<""7D1	
 	
r0  r  c                 $  K   | j                          d{   }| j                  |dd      }||S |dk(  r|dk(  rd}n|dk(  rd}d}|| j                  |      }t        d	t	        |            D ]v  }||   }	| j                  |	d
      }
| j                  |
dd      }| j                  |	d      }|dk(  r||k(  sJ| j                  |	d      c S ||k(  sd| j                  |	d      c S  | j                  |d	i       }| j                  |d      S 7 w)a4  
        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
        N	accountId
account-idrL   rd  r  re  rM   r   r=  subtyperT  r<   )load_accountssafe_value_2ro  rl  rm  rH  rA  )r-  rT  r  r]  rJ  accountsr  rb  rq  r  r=  r  typeFromAccountdefaultAccounts                 r/  fetch_account_id_by_typezhtx.fetch_account_id_by_type  s6     ++--%%fk<H	 6>W$%z)~~f-Hq#h-( 		7AqkG??7F3D&&tY=G"..w?Oxh&++GT::(''66		7 1b955/ .s   DDB"D:D;Dc                   K   | j                  |       d{   }| j                  |dg       }i }i | j                  d<   i | j                  d<   t        dt	        |            D ]  }||   }| j                  |d      }| j                  |      }| j                  |d      }	|	dk(  }
i | j                  d   |<   | j                  |d	g       }i }t        dt	        |            D ]  }||   }| j                  |d
      }| j                  |dd      }|| j                  d   |   |<   || j                  d   |<   | j                  |      }|||| j                  |d      dd| j                  |d      | j                  |d      ddd| j                  |d      dk(  | j                  |d      dk(  | j                  |d      | j                  | j                  | j                  |d                  d	||<    | j                  |||| j                  |d      dk(  dddd|
ddddddddddd|d      ||<    |S 7 'w)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
        NrU  networkChainIdsByNamesnetworkNamesByChainIdsr   rB  	assetTypecryptochainschain	baseChaindisplayNameminDepositAmtrx  minWithdrawAmtmaxWithdrawAmt)depositr   depositStatusallowedwithdrawStatustransactFeeWithdrawwithdrawPrecision)	r=  r<   networkrz  r  r  r   rZ  r|  
instStatusnormal)rw  r   r  )r=  r  r<   r  r  r   rZ  r=   rT  rz  r|  r   )"spotPublicGetV2ReferenceCurrenciesr  r  rl  rm  rA  r  r  network_id_to_codera  r,  r  safe_currency_structure)r-  rJ  rM  rU  rp  rq  r$  
currencyIdr  r  rT  r  r   rx  
chainEntryuniqueChainIdtitlenetworkCodes                     r/  fetch_currencieszhtx.fetch_currencies  s     @@HHJ ~~h313-.13-.q#d)$ >	AGE))%<J**:6D((<I(D;=DLL1248^^E8R8FH1c&k* #AY
 $ 0 0W E**:{MRFS56t<UCHM56}E"55mD&'* $(#3#3J#P#'$
 $(#3#3J@P#Q#'#3#3J@P#Q%	 ##//
OLPYY $ 0 0=M NR[ [++J8MN!%!2!243G3GHXHXYcexHy3z!{%)%6  77 **5,?8K   $#
  $#!
  $#  "$39 F4LI>	~ Q Is   IH>H'I	networkIdcurrencyCodec                    t        | j                  d   j                               }t        |      }|dk(  rt	        | j
                  dz         | j                  | j                  d   ||      }t        t        | '  |      S )Nr  r   z7 networkIdToCode() - markets need to be loaded at first)
r  r  r  rm  r%   r<   rH  r)  r9   r  )r-  r  r  r  
keysLengthnetworkTitler.  s         r/  r  zhtx.network_id_to_code  st    DLL!9:??ABY
?*c cddt||4L'MyZcdS$2<@@r0  r  c                 r   |t        | j                  dz         t        | j                  d   j	                               }t        |      }|dk(  rt        | j                  dz         | j                  | j                  d   |i       }||v r||   S t        t        | +  |      }| j                  |||      S )Nz3 networkCodeToId() requires a currencyCode argumentr  r   z7 networkCodeToId() - markets need to be loaded at first)r)   r<   r  r  r  rm  r%   rH  r)  r9   network_code_to_id)r-  r  r  r  r  uniqueNetworkIdsr  r.  s          r/  r  zhtx.network_code_to_id#  s    #DGG.c$cddDLL!9:??ABY
?*c cdd??4<<8P+QS_acd**#K00 d>{KL??#3\<PPr0  c                   K   | j                          d{    d}| j                  dd|      \  }}| j                  | j                  di       }| j	                  |ddd      }| j                  |ddg      }i }|dk(  }|dk(  }| j                  | j                  dd	d
      }| j                  |dd	|      }	| j                  |dd	|	      }	|	dk(  }
|	d
k(  }d}| j                  d|      \  }}| j                  |dd	g      }|dk(  }|dk(  }|dk(  xs
 |xr |xs |}d}|s|r|rX|r+| j                  | j                  ||             d{   }ni| j                  | j                  ||             d{   }n>| j                          d{    | j                  |dd|       d{   }||d<   | j                  | j                  ||             d{   }n|r*| j                  | j                  ||             d{   }n|rV|r*| j                  | j                  ||             d{   }n| j!                  | j                  ||             d{   }nW|
rU|r*| j#                  | j                  ||             d{   }n)| j%                  | j                  ||             d{   }d|i}| j                  |d      }|s|rB|rt'        dt)        |            D ]  }||   }| j+                  | j-                  |d            }| j                  |d      }i }t'        dt)        |            D ]@  }||   }| j-                  |d      }| j/                  |      }| j1                  |||      ||<   B | j3                  |      ||<    |S | j                  |dg       }t'        dt)        |            D ]@  }||   }| j-                  |d      }| j/                  |      }| j1                  |||      ||<   B | j3                  |      }|S |rt'        dt)        |            D ]  }||   }| j-                  |d      }| j/                  |      }|r| j                  |di       }t'        dt)        |            D ]U  }||   }| j-                  |d      } || j5                  |d      d}!| j+                  |       }|!||<   | j3                  |      }W | j7                         }"| j-                  |d      |"d<   | j-                  |d      |"d<   |"||<   | j3                  |      } |S |rf| j                  |di       }#|rt'        dt)        |            D ]  }||   }| j                  |dd      } | j9                  |       }$| j-                  |d      }| j;                  |      }%| j-                  |$d |%d!         }|h| j7                         }"| j-                  |d"      |"d<   | j-                  |d      |"d<   i }&|"|&|<   |$d   }| j3                  |&      ||<    |S | j7                         }"| j-                  |#d#      |"d<   | j-                  |#d"      |"d$<   | j                  |#dd      }| j/                  |      }|"||<   | j3                  |      }|S |
rt'        dt)        |            D ]i  }||   }| j-                  |d      }| j/                  |      }| j7                         }"| j-                  |d      |"d<   | j-                  |d      |"d<   |"||<   k | j3                  |      }|S 7 7 7 7 7 7 f7 =7 7 7 7 w)%a1  

        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

        query for balance and get the amount of funds available for trading or funds locked in orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.unified]: provide self parameter if you have a recent account with unified cross+isolated margin account
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nri   isUnifiedAccountunifiedFrL   rO   r  r3  r   r   re  rd  rM   r  r=  rU  r   r]  r  rB  margin_assetisolated_swapr  margin_available)r  freemargin_staticr  margin_frozenusedmargin_accountr  r  margin_balancewithdraw_availabletotal)r>  r?  rH  r  r  r  r  rk  %spotPrivateGetV1MarginAccountsBalancerg  *spotPrivateGetV1CrossMarginAccountsBalancer  r  /spotPrivateGetV1AccountAccountsAccountIdBalance3contractPrivateGetLinearSwapApiV3UnifiedAccountInfo1contractPrivatePostLinearSwapApiV1SwapAccountInfo6contractPrivatePostLinearSwapApiV1SwapCrossAccountInfo+contractPrivatePostApiV1ContractAccountInfo+contractPrivatePostSwapApiV1SwapAccountInforl  rm  r`  rA  r  parse_margin_balance_helpersafe_balancera  r  r#  safe_currency)'r-  rJ  rT  r  r  rh  rL   rO   r  r3  r   r   r  re  rd  rM   rM  r  rp  rU  rq  r$  r]  balances	subResultrx  balancer  r  marginAssetr  r  rb  
subBalancer  ri  r[  rB  accountsByCodes'                                          r/  fetch_balancezhtx.fetch_balance1  s      !!!99.$PVWf//$,,C,,V5GTYZ6$6	#BC("++DLL:JIW_`$$W.>	>Z$$V-=y'Ri'X%
!??PVW
F6$4i#@A*,w&("E(D%2C86%)%O%OPTP[P[\cekPl%mmH%)%T%TUYU`U`ahjpUq%rrH((***"&"?"?dDRX"YY	(1%!%!U!UVZVaVabikqVr!ss!UUVZVaVabikqVrssH!%!W!WX\XcXcdkmsXt!uu!%!\!\]a]h]hiprx]y!zz!%!Q!QRVR]R]^egmRn!oo!%!Q!QRVR]R]^egmRn!oo@ )x06q#d), 
BA GE!--d.>.>uh.OPF#uf=H&(I"1c(m4 e"*1+%)%5%5gz%J
#66zB*.*J*J7TXZc*d	$	e
 &*%6%6y%AF6N
Bb K  ??4<q#h-0 [A&qkG!%!1!1':!FJ22:>D#'#C#CGTSY#ZF4L	[
 **62~ } 1c$i( 7Q"..unE#66{C$(OOE?B$OM"1c-&89 	;"/"2#'#3#3G_#M$0$($4$4W>P$Q,
 "&!1!1(!;)3v!%!2!26!:	; #llnG&*&6&6uo&NGFO&*&6&6uo&NGFO+2F<(!..v6F+7z O OOD!R0Eq#d), KA"1gG#11'?L\]H!--h7F!%!1!1'>!JJ#11*=H++FHhv>NOD '"&,,.*.*:*:7DT*U*.*:*:7O*T/1/6t,!'!1)-):):>)Jv#KH # ,,."&"2"25:N"O#'#3#3E;K#L !//~xP
..z:&t**62  1c$i( 'q'!--gx@
..z:,,."&"2"27<N"O"&"2"27O"L&t' &&v.FA	 	"0  nr*Yss vz pos   ]\.D1]\1	*]3\44]\7])\:*-]\=+]] -]1]2)]]-]	]	
)]3]4L]E+]1]4]7]:]=] ]]]	]]c                   K   | j                          d{    d}|| j                  |      }d}| j                  d||      \  }}i }d}|dk(  ro| j                  |d      }|+| j	                  | j                  ||             d{   }n||d<   | j                  | j                  ||             d{   }n_|t        | j                  dz         | j                  |dd      }|||d<   n||d<   | j                  |ddg      }|d	   |d
<   |d   r{d}	| j                  d|      \  }	}|	dn|	}	|	dk(  r*| j                  | j                  ||             d{   }n|	dk(  r| j                  | j                  ||             d{   }n|d   r|dk(  r2|d   |d<   | j                  | j                  ||             d{   }nM|dk(  r*| j                  | j                  ||             d{   }nt!        | j                  dz   |z   dz         | j#                  |d      }
t%        |
t&              r| j#                  |
d      }
| j)                  |
      S 7 N7 7 7 7 7 7 xw)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   rL   clientOrderIdr6  z( fetchOrder() requires a symbol argumentclient_order_idr7  r<   r  r   rd  re  r   rO   r  r]  rN   z fetchOrder() does not support rf  rU  r   )r>  r[  r?  rA  )spotPrivateGetV1OrderOrdersGetClientOrderrg  "spotPrivateGetV1OrderOrdersOrderIdr)   r<   r  r  rk  /contractPrivatePostLinearSwapApiV1SwapOrderInfo4contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo)contractPrivatePostApiV1ContractOrderInfo)contractPrivatePostSwapApiV1SwapOrderInfor/   rH  r   r  parse_order)r-  r<   r]  rJ  r[  rK  rh  rM  r  r  rD  s              r/  fetch_orderzhtx.fetch_orderc  s      !!![[(F
!??fV\]
F
  ,,V_EM( "&!O!OPTP[P[\cekPl!mm&(
#!%!H!HU\^dIe!ff~'2\(\]] ..v7H/ZM$&(
#-:)*6,=+OP'-d|GO$h!
%)%G%GV\%]"
F)3);W*
+%)%Y%YZ^ZeZefmouZv%wwH7*%)%^%^_c_j_jkrtz_{%||H	")(.z(:GH%%)%S%STXT_T_`gioTp%qqH6)%)%S%STXT_T_`gioTp%qqH&tww1R'RU_'_bl'lmm| &1eT"OOE1-E&&q 	"4 n g   x|  rqs~   I6I$A2I6	I'
/I69I*:B'I6!I-".I6I0;I6I2.I6;I4<A)I6'I6*I6-I60I62I64I6c                     d }||v r||   }n| j                         }|d   dk(  r| j                  |d      |d<   |d   dk(  r| j                  |d      |d<   |S )NrT  r2  r  r  frozenr  )r  rA  )r-  r  r  rp  r  s        r/  r  zhtx.parse_margin_balance_helper-  sk    6>TlGllnG6?g%"..w	BGFO6?h&"..w	BGFOr0  c                 t  K   | j                  | j                  dd      }|dk(  r|t        | j                  dz         | j	                          d {    d }d|i}|| j                  |      }|d   |d<   |||d<   | j                  |d      |d	<   | j                  d	||      \  }}|||d
<   d }	|dk(  r*| j                  | j                  ||             d {   }	n)| j                  | j                  ||             d {   }	| j                  |	dg       }
| j                  |
|||      S 7 7 W7 /w)Nr  r  z) fetchOrders() requires a symbol argumentstatesr<   r]  r^  i L
r_  r]  rU  )rA  r  r)   r<   r>  r[  r  ri  spotPrivateGetV1OrderOrdersrg  spotPrivateGetV1OrderHistoryr  parse_orders)r-  r  r]  rT  r  rJ  methodr[  rh  rM  rU  s              r/  fetch_spot_orders_by_stateszhtx.fetch_spot_orders_by_states9  sa    !!$,,0KMop77~'2](]^^!!! f
" [[(F &tGH$)GL!"&((52E"FGJ22:wO#GFO77!==dkk'SY>Z[[H!>>t{{7TZ?[\\H6 ~~h3  vue<<y 	"< \\s7   AD8D2B	D8D4)D8D6,D84D86D8c                 H   K   | j                  d||||       d {   S 7 w)NzGpre-submitted,submitted,partial-filled,filled,partial-canceled,canceledr  r-  r]  rT  r  rJ  s        r/  fetch_spot_orderszhtx.fetch_spot_orders|  sF     556  BH  JO  QV  X^  _  _  	_  _   " "c                 H   K   | j                  d||||       d {   S 7 w)Nz filled,partial-canceled,canceledr  r  s        r/  fetch_closed_spot_orderszhtx.fetch_closed_spot_orders  s*     556XZ`bginpvwwwwr  c                   K   |t        | j                  dz         | j                          d {    | j                  |      }ddd}d }| j	                  |dd      }| j                  |d      }	| j                  |dd	      }
| j                  |g d
      }|s|	s|
r|||d<   |d   |d<   d|d<   n|||d<   |d   |d<   d|d<   | j                  d||      \  }}|d   rd }| j                  d|      \  }}|dn|}|dk(  r|r+| j                  | j                  ||             d {   }n|	r+| j                  | j                  ||             d {   }n|
r+| j                  | j                  ||             d {   }nX| j                  | j                  ||             d {   }n-|dk(  r'|r+| j                  | j                  ||             d {   }n|	r+| j!                  | j                  ||             d {   }n|
r+| j#                  | j                  ||             d {   }n| j%                  | j                  ||             d {   }nu|d   ro|d   r|r+| j'                  | j                  ||             d {   }n=|	r+| j)                  | j                  ||             d {   }n|
r*| j+                  | j                  ||             d {   }n| j-                  | j                  ||             d {   }n|d   r|d   |d<   |r*| j/                  | j                  ||             d {   }n|	r*| j1                  | j                  ||             d {   }nU|
r*| j3                  | j                  ||             d {   }n)| j5                  | j                  ||             d {   }| j                  |d      }t7        |t8              s| j                  |dg       }| j;                  ||||      S 7 7 7 7 7 7 Y7 /7 7 7 7 ~7 T7 -7 7 7 7 zw) Nz1 fetchContractOrders() requires a symbol argumentr   r@  )r`  r   stopr  stopLossTakeProfitr  Fr  r  r  r  rc  r<   r  r"  r  ra  r   r   rT  rb  r   fetchContractOrdersrd  re  r   rN   rO   r  r]  rU  orders)r)   r<   r>  r[  safe_bool_2rH  r  r  ri  rk  6contractPrivatePostLinearSwapApiV1SwapTriggerHisordersrg  3contractPrivatePostLinearSwapApiV1SwapTpslHisorders4contractPrivatePostLinearSwapApiV1SwapTrackHisorders/contractPrivatePostLinearSwapApiV3SwapHisorders;contractPrivatePostLinearSwapApiV1SwapCrossTriggerHisorders8contractPrivatePostLinearSwapApiV1SwapCrossTpslHisorders9contractPrivatePostLinearSwapApiV1SwapCrossTrackHisorders4contractPrivatePostLinearSwapApiV3SwapCrossHisorders0contractPrivatePostSwapApiV1SwapTriggerHisorders-contractPrivatePostSwapApiV1SwapTpslHisorders.contractPrivatePostSwapApiV1SwapTrackHisorders)contractPrivatePostSwapApiV3SwapHisorders0contractPrivatePostApiV1ContractTriggerHisorders-contractPrivatePostApiV1ContractTpslHisorders.contractPrivatePostApiV1ContractTrackHisorders)contractPrivatePostApiV3ContractHisordersr   r  r  )r-  r]  rT  r  rJ  r[  rh  rM  r  r  r  r  r  s                r/  fetch_contract_orderszhtx.fetch_contract_orders  s    >#DGG.a$abb!!!V$ 	
 ""669=!__V5IJ>>&*e<6#XY(H ',$'-d|GO$%'GM" (-%"(,GJGFO22:wO(J!%!C!CDY[a!bJ%/%7jJZ'%)%`%`aealalmtv|a}%~~H'%)%]%]^b^i^ijqsy^z%{{H%)%^%^_c_j_jkrtz_{%||H%)%Y%YZ^ZeZefmouZv%wwHw&%)%e%efjfqfqry  |B  gC  &D   DH'%)%b%bcgcncnovx~c  &A   AH%)%c%cdhdodopwy  eA  &B   BH%)%^%^_c_j_jkrtz_{%||HIf~%)%Z%Z[_[f[fgnpv[w%xxH'%)%W%WX\XcXcdkmsXt%uuH%)%X%XY]YdYdelntYu%vvH%)%S%STXT_T_`gioTp%qqH!$*:$6!%)%Z%Z[_[f[fgnpv[w%xxH'%)%W%WX\XcXcdkmsXt%uuH%)%X%XY]YdYdelntYu%vvH%)%S%STXT_T_`gioTp%qqH^ 62&$'__VXr:F  >>q 	"F  {|w  D  A  B|  yuvq  yuvqs1  .QP.C;Q,P1-,QP4,QP7*Q1P:22Q$P=%,QQ ,Q>Q?*Q)Q*7Q!Q	",QQ,Q;Q<)Q%Q&8QQ+Q
Q+Q6Q7)Q Q!AQ1Q4Q7Q:Q=Q QQQ	QQQQQQQQc           	      n   K   ddi}| j                  |||| j                  ||             d {   S 7 w)Nr   z5,6,7)r/  rg  )r-  r]  rT  r  rJ  rh  s         r/  fetch_closed_contract_ordersz htx.fetch_closed_contract_orders_  s>     g
 //udkkRY[aFbccccs   ,535c                 p  K   | j                          d{    d}|| j                  |      }d}| j                  d||      \  }}|dk(  xs |dk(  }|r |t        | j                  dz   |z   dz         |r| j                  ||||       d{   S | j                  ||||       d{   S 7 7 "7 w)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   rN   rO   z. fetchOrders() requires a symbol argument for  orders)r>  r[  r?  r)   r<   r/  r  )r-  r]  rT  r  rJ  r[  rK  r   s           r/  fetch_orderszhtx.fetch_orderse  s     * !!![[(F
!??vW]^
F&(EjH.D#DGG.^$^ak$knw$wxx33FE5&QQQ//ufMMM 	" RMs4   B6B0A8B6B2B6+B4,B62B64B6c                   K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||d       d{   S d}|| j                  |      }d}| j	                  d||      \  }}|dk(  r| j                  ||||       d{   S | j                  ||||       d{   S 7 7 p7 $7 
w)aQ  

        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>`
        NFrp   r\  rB   rL   )r>  r  rh  r[  r?  r  r1  )r-  r]  rT  r  rJ  r\  r[  rK  s           r/  fetch_closed_orderszhtx.fetch_closed_orders  s     & !!!88ATV`a&::;NPVX]_dflnqrrr[[(F
!??@SU[]cd
F66vueVTTT::65%QWXXX 	" s UXsF   CB=7CB?ACCC8C9C?CCCc                 V
  K   | j                          d{    d}|| j                  |      }i }d}| j                  d||      \  }}d}|dk(  r||d   |d<   | j                  |d      }	|	w| j	                          d{    t        dt        | j                              D ]=  }
| j                  |
   }| j                  |d      dk(  s(| j                  |d      }	|	= n |	|d<   |||d	<   | j                  |d      }| j                  | j                  ||             d{   }n||t        | j                  d
z         |||d<   |d   |d<   | j                  |dd      }| j                  |d      }| j                  |dd      }| j                  |g d      }|d   rd}| j!                  d|      \  }}|dn|}|dk(  r|r+| j#                  | j                  ||             d{   }n|r+| j%                  | j                  ||             d{   }n|r+| j'                  | j                  ||             d{   }nX| j)                  | j                  ||             d{   }n-|dk(  r'|r+| j+                  | j                  ||             d{   }n|r+| j-                  | j                  ||             d{   }n|r+| j/                  | j                  ||             d{   }n| j1                  | j                  ||             d{   }nu|d   ro|d   r|r+| j3                  | j                  ||             d{   }n=|r+| j5                  | j                  ||             d{   }n|r*| j7                  | j                  ||             d{   }n| j9                  | j                  ||             d{   }n|d   r|d   |d<   |r*| j;                  | j                  ||             d{   }n|r*| j=                  | j                  ||             d{   }nU|r*| j?                  | j                  ||             d{   }n)| jA                  | j                  ||             d{   }| j                  |d      }tC        |tD              s| j                  |dg       }| jG                  ||||      S 7 7 u7 7 7 7 7 7 _7 57 7 7 7 7 Z7 37 7 7 7 w)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   rL   r<   r]  r  r   rT  r]  z- fetchOpenOrders() requires a symbol argumentrc  r  r  r  r  r  Fr  r   rd  re  r   rN   rO   r  rU  r  )$r>  r[  r?  rA  r  rl  rm  r  r  spotPrivateGetV1OrderOpenOrdersrg  r)   r<   r  rH  r  rk  7contractPrivatePostLinearSwapApiV1SwapTriggerOpenorders4contractPrivatePostLinearSwapApiV1SwapTpslOpenorders5contractPrivatePostLinearSwapApiV1SwapTrackOpenorders0contractPrivatePostLinearSwapApiV1SwapOpenorders<contractPrivatePostLinearSwapApiV1SwapCrossTriggerOpenorders9contractPrivatePostLinearSwapApiV1SwapCrossTpslOpenorders:contractPrivatePostLinearSwapApiV1SwapCrossTrackOpenorders5contractPrivatePostLinearSwapApiV1SwapCrossOpenorders1contractPrivatePostSwapApiV1SwapTriggerOpenorders.contractPrivatePostSwapApiV1SwapTpslOpenorders/contractPrivatePostSwapApiV1SwapTrackOpenorders*contractPrivatePostSwapApiV1SwapOpenorders1contractPrivatePostApiV1ContractTriggerOpenorders.contractPrivatePostApiV1ContractTpslOpenorders/contractPrivatePostApiV1ContractTrackOpenorders*contractPrivatePostApiV1ContractOpenordersr   r  r  )r-  r]  rT  r  rJ  r[  rh  rK  rM  r  rq  r  r  r  r  r  r  s                    r/  fetch_open_orderszhtx.fetch_open_orders  s    " !!![[(F
!??@QSY[ab
F!$*4L!((>I ((***q#dmm"45 "A"mmA.G''8FB$($4$4Wd$C	$0!" %.GL! "'YYv|4F!AA$++gW]B^__H~'2a(abb ',$'-d|GO$&&vvyAG!%9M!N~~fj%@HYYv'\]Fh!
%)%G%GHY[a%b"
F)3);W*
+)-)e)efjfqfqry  |B  gC  *D  $D+)-)b)bcgcncnovx~c  *A  $A!)-)c)cdhdodopwy  eA  *B  $B)-)^)^_c_j_jkrtz_{)|#|7*)-)j)jkokvkvw~  AG  lH  *I  $I+)-)g)ghlhshst{  ~D  iE  *F  $F!)-)h)himititu|  E  jF  *G  $G)-)c)cdhdodopwy  eA  *B  $B	"&>)-)_)_`d`k`klsu{`|)}#}+)-)\)\]a]h]hiprx]y)z#z!)-)])]^b^i^ijqsy^z){#{)-)X)XY]YdYdelntYu)v#vH%(.z(:GH%)-)_)_`d`k`klsu{`|)}#}+)-)\)\]a]h]hiprx]y)z#z!)-)])]^b^i^ijqsy^z){#{)-)X)XY]YdYdelntYu)v#vr 62&$'__VXr:F  >>U 	" + `" $D $A $B#| $I $F $G $B $~#z#{#v $~#z#{#vsd  T)S4A+T)S7A
T)T)#AT)(S:)C	T)2S=3,T)T  ,T)T*T)7T82T)*T	+,T)T,T)T*T)/T07T)'T(,T)T,T)T)T)+T,8T)$T!%+T)T#+T)<T%=)T)&T''AT)7T):T)=T) T)T)T)	T)T)T)T)T)T)T)T)!T)#T)%T)'T)r   c                 J    ddddddddddddddd}| j                  |||      S )Nr  canceledclosed	canceling)zpartial-filledzpartial-canceledfilledrK  	submittedr  r  23456711rA  r-  r   statusess      r/  parse_order_statuszhtx.parse_order_status  sL     % *"!
$ &&99r0  rD  c           	         | j                  |dd      }| j                  | j                  |dd            }|d}| j                  |g d      }| j                  |d      }| j                  |d      }d	|v r|d	   j	                  d
      }|d   }|d   }| j                  |dd      }	| j                  |	|      }| j                  |g d      }
| j                  |dd      }d }d }|'|j                  d      dk\  r| j                  |d      }n'| j                  |dd      }| j                  |g d      }| j                  |g d      }| j                  |dd      }| j                  |dd      }| j                  |d|      }d }|<d }| j                  |d      }|| j                  |      }n|dk(  r|d   n|d    }||d!}| j                  |d"      }| j                  |d#      }| j                  |d$      }d }|	|dk(  rd%nd&}| j                  i d'|d(|d)|d*|
d+| j                  |
      d,d d|d   d	|d-d d.d d/|d|d0| j                  |d1d2      d3|d4|d|d5|d ||||d6|      S )7Nerr_codeerr-coder  r   rejected)r<   order_id_strr6  r!  order_price_typerT  r  r   r   r  r]  )r5  r4  r  r  client-order-idr[  field-cash-amountvolumerw  )zfilled-cash-amountrb  r<  )r:  zfield-amountr;  r  order_pricer=  z
field-feesrZ  r?  sellr  r  rA  trade_avg_pricerg  reduce_onlyFTr=  r<   r  r  rQ  lastTradeTimestampr  postOnlyr"  r  
stop-pricetrigger_pricer  r}  rN  )	remainingr   
reduceOnlyrZ  rg  )r  rZ  rH  rA  r  r#  safe_integer_nfindr  rH  r  
safe_orderr  )r-  rD  r[  rejectedCreateOrdersr   r<   r"  rT  	orderTyperb  r  r  r}  rw  rN  r  rN  rZ  rP  rO  r  rg  reduceOnlyIntegerrm  s                           r/  r  zhtx.parse_order  sb   N  $11%ZP((););E7H)UV+F'IJ{3'9:U?f++C0IQ<DQ<D%%e_hG!!(F3''/Z[	**52CE[\499X#6!#;##E+>?D''xBF%%e-jkD##E+\]""5'=A$$UM<H""5%9K ,,UK@M("55mD26&.fWovf~'C ""5*;<1 --e]C
(#4#9J  
E 
" 
 ] 
 	 

 Y/ 
 !$ 
 fX& 
 D 
 4 
  
 D 
 U 
 D..ulOT 
 w 
 D 
  f! 
" f# 
$ $- 
. / 	r0  r}  c                    K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d<   | j	                  |dd|d|       d{   S 7 U7 w)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>`
        NrL   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r[  buy)r>  r[  r/   r<   create_order)r-  r]  r}  rJ  r[  s        r/  !create_market_buy_order_with_costz%htx.create_market_buy_order_with_cost  sy      !!!V$f~tww)ddee6;23&&vxdFSSS 	"
 Ts"   A0A,AA0'A.(A0.A0r"  rw  r  c	                    K   |t        | j                  dz         |t        | j                  dz         ||d<   ||d<   | j                  ||||||       d{   S 7 w)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 argumenttrailingPercenttrailingTriggerPrice)r)   r<   rv  )	r-  r]  rT  r"  rw  r  ry  rz  rJ  s	            r/  create_trailing_percent_orderz!htx.create_trailing_percent_order  su      "#DGG.q$qrr'#DGG.v$vww$3 !)=%&&&vtT65&QQQQs   AA!AA!c                 .  K   | j                          d{    | j                          d{    | j                  |      }d}| j                  d|      \  }}| j	                  |d   ||       d{   }	|	|d   d}
|j                  dd      }|j                  dd      }| j                  | j                  |d   i       }| j                  |g d	      }|/| j                  |d
i       }||v rt        | j                  dz         |dk(  rdnd}| j                  |d|      }| j                  ||      |
d<   ||
d<   |dk(  s|dk(  rd|z   }n(|dk7  r#|dk7  rt        | j                  dz   |z   dz         d}| j                  |dk(  |dk(  |      \  }}|rd}| j                  |dd      }|dk(  r|dz   }n|dk(  rd}|d z   |z   |
d<   | j                  |d!d"      }|F| j                  | j                  d#i       }| j                  |d      }|| j!                         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,}| j#                  |dd-d,      \  }}| j%                  |d.      }| j'                  |d.      }|| j)                  ||      }nw|rc|t+        | j                  d/z         | j-                  |      }| j-                  |      }| j)                  |t/        j0                  ||            }n| j)                  ||      }||
d0<   n| j)                  ||      |
d0<   | j                  |d1i       }||v r| j                  ||      |
d2<   | j'                  |g d3      }| j3                  |
|      S 7 v7 a7 w)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^   rT  r<   )r  r]  zbuy- zsell-)r  	stopPricerj  r  z: createOrder() requires a triggerPrice for a trigger orderre  ltegteoperatorrj  r  r  zstop-r  r  z  createOrder() does not support r3  r[  r  r  r  r  z-fokr  r  r  r  ra  r  rd  zsuper-margin-apisourcere  z
margin-apic2czc2c-margin-apiru  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 argumentrw  r  r  )r  r~  rj  r  ra  r  r  )r>  r  r[  rk  r  replacerH  r  rH  r)   r<   rA  price_to_precisionr/   handle_post_onlyr  uuidr  ra  r  amount_to_precisionr-   number_to_stringr7   
string_mulrg  )r-  r]  rT  r"  rw  r  rJ  r[  r  r  rh  rr  r  r  r  defaultOperatorstopOperatorri  r  r  r  brokerIdquoteAmountr  r}  rL  rK  r  s                               r/  create_spot_order_requestzhtx.create_spot_order_request  s1     !!!  """V$
!??vV
F77v
TZ[[	 $Tl
 LL,	%%gr2	//$,,vC))&2]^!__W6FKNN*'2n(noo(,eUO++FJPL$($;$;FL$QGL!".GJW$){*B#i/	|+)?O2O"477-O#ORV#VYb#bcc00h1F	UbHbdjk&%I&&v}eD%!F*IE!I*y0**6?DUV __T\\8R@F''5H)1DIIK)?G%&)6G%&  2GH:% ,GH5  0GH!K04-8<8U8UV\^k  nQ  SW  9X5-v##FF3DYYvv.F"66vtD2=&tww  2m  (m  n  n $(#8#8#@L"&"7"7">K"&":":67CUCUVbdoCp"qK"66vvF +GH $ 8 8 HGH//'3DbI'#66vuEGG6  $N  O{{7F++q 	"" \s3   NNNNAN4N5LNNNc                    | j                  |      }|d   | j                  ||      |d}d}	| j                  |dk(  |dk(  |      \  }	}|	rd}| j                  |dd      }
|
dk(  rd	}n|
d
k(  rd}| j	                  |g d      }| j                  |dd      }| j                  |dd      }| j                  |dd      }| j                  |d|      }|du}|du}|du}|du}|rH| j                  |ddd      }||d<   | j                  ||      |d<   || j                  ||      |d<   n|s|rf|r2||d<   | j                  ||      |d<   || j                  ||      |d<   n||d<   | j                  ||      |d<   || j                  ||      |d<   n|rFt        j                  |d      }| j                  |      |d<   ||d<   | j                  |dd       |d<   nV| j                  |d!d"      }|||d!<   | j                  |d"g      }|d#k(  s|dk(  s
|d	k(  s|dk(  r| j                  ||      |d$<   | j                  |d%d&d'      }|s(|s&|rd(|d&<   | j                  |g d)d(      |d*<   |s||d<   | j!                  |d+d'      }|r|rd,|d-<   nd.|d-<   | j#                  | j$                  d/i       }| j                  |d      }||d0<   | j                  |g d1      }| j'                  ||      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  rc  r!  Nr[  	post_onlyr  r  r  fokr  r  r  r~  rk  r
  sl_trigger_pricer  tp_trigger_pricery  callback_raterz  triggerTypetrigger_typelerk  rd  sl_order_price_typesl_order_pricetp_order_price_typetp_order_price100active_pricer`  formula_pricer  r  r  r  rm  rg  Fr   )	leverRate
lever_rater  r  r  r  offsetr  r  channel_code)rm  r  r~  r
  r  r  r  r  r  ry  rz  r  )r[  r  r  rA  safe_number_nsafe_number_2r  ra  r  r7   
string_divparse_to_numericrX  r  r  rn  r  rH  r  rg  )r-  r]  rT  r"  rw  r  rJ  r[  rh  ri  r  r  stopLossTriggerPricetakeProfitTriggerPricery  rz  isTrailingPercentOrder	isTriggerisStopLossTriggerOrderisTakeProfitTriggerOrderr  trailingPercentStringr  rm  r  r  r  s                              r/  create_contract_order_requestz!htx.create_contract_order_request  s    V$#D\..vv>

 001A4;CVX^_&D&&v}eD%DE!D))&2`a#11&/K]^!%!3!3F<MOa!b,,V5FX#//8NPUV!0!< ,	!5T!A#9#E ,,V]NTXYK&1GN#'+'>'>v|'TGO$ )-)@)@)O&#'?%15-..2.E.EfNb.c*+$040G0GPU0VG,-15-..2.E.EfNd.e*+$040G0GPU0VG,-#$+$6$6$N!'+'<'<=R'SGO$&:GN#*.*:*:6CUWf*gG&' //8I?[M(-:)*6O+<=w$%-45=DKDW#'#:#:65#I %%flM5Q
%.F)*&$($7$7@gij$kGL!).2*+%8$+!$*!x<##FD1"*6  $_  `{{7F++r0  c                 z  K   | j                          d{    | j                  |      }| j                  |g d      }| j                  |dd      }	| j                  |dd      }
| j	                  |d      }|du}|du}|	du}|
du}d}|d   rS|rt        | j                  d	z         | j                  ||||||       d{   }| j                  |       d{   }nG| j                  ||||||      }|d
   rd}| j                  d|      \  }}|dn|}|dk(  rt|r| j                  |       d{   }n|s|r| j                  |       d{   }n|r| j                  |       d{   }n| j                  |       d{   }n|dk(  r|r| j                  |       d{   }nr|s|r| j!                  |       d{   }nS|r| j#                  |       d{   }n6| j%                  |       d{   }n|d   r| j'                  |d      }|t)        | j                  dz         |d   rp|r| j+                  |       d{   }n|s|r| j-                  |       d{   }n|r| j/                  |       d{   }n| j1                  |       d{   }nt|d   ro|r| j3                  |       d{   }nS|s|r| j5                  |       d{   }n5|r| j7                  |       d{   }n| j9                  |       d{   }d}d}|d   rY| j;                  i d|d| j'                  |d      dddd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'| j=                  |di       }| j=                  |d&i       }n<|r'| j=                  |di       }| j=                  |d'i       }n| j=                  |di       }| j?                  ||      S 7 7 C7 -7 7 7 7 7 g7 K7 17 7 7 7 7 }7 _7 D7 +7 w)(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>`
        Nr  r
  r  r  r  ry  rL   z@ createOrder() does not support trailing orders for spot marketsr   r^   rd  re  r   r  z createOrder() requires an extra parameter params["offset"] to be set to "open" or "close" when placing orders in inverse marketsrN   rO   r=  r<   rU  r  rQ  rh  r   r]  rT  r"  r  rw  rN  rl  r}  rg  rZ  r  r  sl_ordertp_order) r>  r[  r  r  ra  r/   r<   r  !spotPrivatePostV1OrderOrdersPlacer  rk  2contractPrivatePostLinearSwapApiV1SwapTriggerOrder/contractPrivatePostLinearSwapApiV1SwapTpslOrder0contractPrivatePostLinearSwapApiV1SwapTrackOrder+contractPrivatePostLinearSwapApiV1SwapOrder7contractPrivatePostLinearSwapApiV1SwapCrossTriggerOrder4contractPrivatePostLinearSwapApiV1SwapCrossTpslOrder5contractPrivatePostLinearSwapApiV1SwapCrossTrackOrder0contractPrivatePostLinearSwapApiV1SwapCrossOrderrA  r)   ,contractPrivatePostSwapApiV1SwapTriggerOrder)contractPrivatePostSwapApiV1SwapTpslOrder*contractPrivatePostSwapApiV1SwapTrackOrder%contractPrivatePostSwapApiV1SwapOrder,contractPrivatePostApiV1ContractTriggerOrder)contractPrivatePostApiV1ContractTpslOrder*contractPrivatePostApiV1ContractTrackOrder%contractPrivatePostApiV1ContractOrderrp  rH  r  )r-  r]  rT  r"  rw  r  rJ  r[  r  r  r  ry  r  r  r  r  rM  spotRequestcontractRequestr  r  rU  rp  s                          r/  rv  zhtx.create_ordern  s    J !!!V$))&2`a#11&/K]^!%!3!3F<MOa!b**63DE!0!< ,	!5T!A#9#E &>%"477-o#opp $ > >vtTSY[`bh iiK!CCKPPH"@@tU[]bdjkOh!
.2.P.PQ^`o.p+
O)3);W*
+ )-)`)`ap)q#q/3K)-)])]^m)n#n/)-)^)^_n)o#o)-)Y)YZi)j#j7* )-)e)efu)v#v/3K)-)b)bcr)s#s/)-)c)cds)t#t)-)^)^_n)o#o	"))&(;>+DGG  7z  -z  {  {&> )-)Z)Z[j)k#k/3K)-)W)WXg)h#h/)-)X)XYh)i#i)-)S)STc)d#dH% )-)Z)Z[j)k#k/3K)-)W)WXg)h#h/)-)X)XYh)i#i)-)S)STc)d#d> &>?? $$d&&x8$ T$ D	$
 %d$ $$ $$ $ $ $ &$ $$ T$ $ $$  t!$"  #$$ 4%$& ' ( $??8VR8D__T:r:F%??8VR8D__T:r:F__Xvr:F//w 	" jP $r#n#o#j $w#s#t#o $l#h#i#d $l#h#i#dsW  P;PB+P;PP;PAP;6P7P;PP;2P3P;P"P;0P1P;PP;,P-P;P AP;P#P;9P&:P;P)P;/P,0 P;P/P;.P2/P;
P5P;$P8%CP;P;P;P;P;P;P;P;P;P; P;#P;&P;)P;,P;/P;2P;5P;8P;r  c           	      x  K   | j                          d{    g }d}d}d}t        dt        |            D ]B  }||   }| j                  |d      }	||	}n||	k7  rt	        | j
                  dz         | j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d	i       }| j                  d
|      }|d   }|"||}n||k7  rt	        | j
                  dz         | j                  |      }d}|d   r| j                  |	|
||||       d{   }n| j                  |	|
||||      }| j                  |d      }|j                  |       E i }d}|d   r| j                  |       d{   }n||d<   |d   rD|dn|}|dk(  r| j                  |       d{   }na|dk(  r\| j                  |       d{   }nB|d   r=|d   r| j!                  |       d{   }n|d   r| j#                  |       d{   }d}|d   r| j                  |dg       }nK| j                  |di       }| j                  |dg       }| j                  |dg       }| j%                  ||      }| j'                  ||      S 7 7 p7 7 7 7 7 w)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   r]  z; createOrders() requires all orders to have the same symbolrT  r"  rw  r  rJ  r_   zS createOrders() requires all orders to have the same margin mode(isolated or cross)rL   r  orders_datar   rd  re  r   rN   rO   rU  successerrors)r>  rl  rm  rA  r*   r<   rH  rk  r[  r  r  r  r  privatePostOrderBatchOrders0contractPrivatePostLinearSwapApiV1SwapBatchorder5contractPrivatePostLinearSwapApiV1SwapCrossBatchorder*contractPrivatePostSwapApiV1SwapBatchorder*contractPrivatePostApiV1ContractBatchorderr  r  )r-  r  rJ  ordersRequestsr]  r[  r  rq  rawOrderrb  rT  r"  rw  r  orderParamsmarginResultcurrentMarginModeorderRequestrh  rM  rp  rU  r  r  s                           r/  create_orderszhtx.create_orders  s     !!!
q#f+& 	0AayH''(;H~!X%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAK==nkZL ,Q ,%!2J!%66(  4I  *I  J  J[[(FLf~%)%C%CHdTXZ`bgit%uu#AA(DRVX^`egrs99\<@L!!,/9	0: &>!==nMMH%3GM"h)3);W*
+%)%Z%Z[b%ccH7*%)%_%_`g%hhH	"&>%)%T%TU\%]]HH%%)%T%TU\%]]HT &>__Xvr:F??8VR8DoodIr:G__T8R8F&&w7F  00I 	":  v N  dh  ^]s~   J:J)D%J:<J,=AJ:J/.J:
J2J:)J4*#J:J6J:,J8-A=J:,J:/J:2J:4J:6J:8J:c                 
  K   | j                          d{    d}|| j                  |      }d}| j                  d||      \  }}i }d}|dk(  r| j                  |dd      }|0||d<   | j	                  | j                  ||             d{   }n||d<   | j                  |ddg      }| j                  | j                  ||             d{   }n|t        | j                  dz         | j                  |dd      }|||d	<   n||d<   | j                  |ddg      }|d
   r	|d   |d<   n|d   |d<   | j                  |dd      }	| j                  |d      }
| j                  |dd      }| j                  |g d      }|d   rd}| j                  d|      \  }}|dn|}|dk(  r|	r+| j                  | j                  ||             d{   }n|
r+| j                  | j                  ||             d{   }n|r+| j!                  | j                  ||             d{   }no| j#                  | j                  ||             d{   }nD|dk(  r>|	r+| j%                  | j                  ||             d{   }n|
r+| j'                  | j                  ||             d{   }n|r+| j)                  | j                  ||             d{   }n| j+                  | j                  ||             d{   }n|d   rh|d   r|	r+| j-                  | j                  ||             d{   }nT|
r+| j/                  | j                  ||             d{   }n'|r*| j1                  | j                  ||             d{   }n| j3                  | j                  ||             d{   }n|d
   r|	r*| j5                  | j                  ||             d{   }n|
r*| j7                  | j                  ||             d{   }nt|r*| j9                  | j                  ||             d{   }nH| j;                  | j                  ||             d{   }nt=        | j                  dz   |z   dz         | j                  | j?                  ||      |dd      S 7 7 A7  7 7 7 7 7 R7 (7 7 7 7 w7 M7 &7 7 7 7 {w)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>`
        NrV   rL   ra  r  r6  z) cancelOrder() requires a symbol argumentr  r7  rO   r  r]  r<   r  r  r  r  r  Fr  r   rd  re  r   rN   z  cancelOrder() does not support rf  rK  )r<   r   ) r>  r[  r?  r  /spotPrivatePostV1OrderOrdersOrderIdSubmitcancelrg  r  3spotPrivatePostV1OrderOrdersSubmitCancelClientOrderr)   r<   r  rH  r  rk  3contractPrivatePostLinearSwapApiV1SwapTriggerCancel0contractPrivatePostLinearSwapApiV1SwapTpslCancel1contractPrivatePostLinearSwapApiV1SwapTrackCancel,contractPrivatePostLinearSwapApiV1SwapCancel8contractPrivatePostLinearSwapApiV1SwapCrossTriggerCancel5contractPrivatePostLinearSwapApiV1SwapCrossTpslCancel6contractPrivatePostLinearSwapApiV1SwapCrossTrackCancel1contractPrivatePostLinearSwapApiV1SwapCrossCancel-contractPrivatePostSwapApiV1SwapTriggerCancel*contractPrivatePostSwapApiV1SwapTpslCancel+contractPrivatePostSwapApiV1SwapTrackCancel&contractPrivatePostSwapApiV1SwapCancel-contractPrivatePostApiV1ContractTriggerCancel*contractPrivatePostApiV1ContractTpslCancel+contractPrivatePostApiV1ContractTrackCancel&contractPrivatePostApiV1ContractCancelr/   r  )r-  r<   r]  rJ  r[  rK  rh  rM  r  r  r  r  r  s                r/  cancel_orderzhtx.cancel_order  sI     !!![[(F
!??vW]^
F
  ..v7H/ZM$&(
#!%!U!UVZVaVabikqVr!ss-:)*6,=+OP!%!Y!YZ^ZeZefmouZv!ww~'2](]^^ ..v7H/ZM$&(
#-:)*6,=+OPh$*:$6!+1$<(&&vvyAG!%9M!N~~fj%@HYYv'\]Fh!
%)%G%GW]%^"
F)3);W*
+)-)a)abfbmbmnuw}b~)#+)-)^)^_c_j_jkrtz_{)|#|!)-)_)_`d`k`klsu{`|)}#})-)Z)Z[_[f[fgnpv[w)x#x7*)-)f)fgkgrgrsz  }C  hD  *E  $E+)-)c)cdhdodopwy  eA  *B  $B!)-)d)deiepepqx  {A  fB  *C  $C)-)_)_`d`k`klsu{`|)}#}	"&>)-)[)[\`\g\ghoqw\x)y#y+)-)X)XY]YdYdelntYu)v#v!)-)Y)YZ^ZeZefmouZv)w#w)-)T)TUYU`U`ahjpUq)r#rH%)-)[)[\`\g\ghoqw\x)y#y+)-)X)XY]YdYdelntYu)v#v!)-)Y)YZ^ZeZefmouZv)w#w)-)T)TUYU`U`ahjpUq)r#r"477-O#OR\#\_i#ijj( {{4++Hf= @
  	W 	". t x0 $@#|#}#x $E $B $C#} $z#v#w#r $z#v#w#rsW  TSA8TSATSDTS,TS,T2S3*TS2TS",T=S%>,T*S(+*TS+7TS.,T:S1;,T'S4()TS70TS:+T.S</+TS>)TT A	TTTTTTT"T%T(T+T.T1T4T7T:T<T>T Tc                   K   | j                          d{    d}|| j                  |      }d}| j                  d||      \  }}i }d}|dk(  r| j                  |dd      }| j                  |dd|      }|t	        |t
              r|g|d<   n6||d<   n0t	        |t
              r|g|d<   n||d<   | j                  |g d	      }| j                  | j                  ||             d{   }n*|t        | j                  d
z         | j                  |dd      }| j                  |dd|      }|dj                  |      |d<   n||d<   | j                  |g d      }|d   r	|d   |d<   n|d   |d<   | j                  |dd      }	| j                  |d      }
| j                  |g d      }|d   r2d}| j                  d|      \  }}|dn|}|dk(  r|	r+| j!                  | j                  ||             d{   }n|
r+| j#                  | j                  ||             d{   }n| j%                  | j                  ||             d{   }n|dk(  r|	r+| j'                  | j                  ||             d{   }n|
r+| j)                  | j                  ||             d{   }n]| j+                  | j                  ||             d{   }n2|d   r|d   r|	r*| j-                  | j                  ||             d{   }n|
r*| j/                  | j                  ||             d{   }n| j1                  | j                  ||             d{   }n|d   r|	r*| j3                  | j                  ||             d{   }nt|
r*| j5                  | j                  ||             d{   }nH| j7                  | j                  ||             d{   }nt9        | j                  dz   |z   dz         | j;                  |d       }| j=                  |      S 7 )7 W7 E7 7 7 7 7 q7 <7 7 7 7 7 jw)!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>`
        NrW   rL   ra  r  client-order-idsclientOrderIdsz	order-ids)ra  r  r  r  z* cancelOrders() requires a symbol argumentr  client_order_ids,r7  )r  r  r  r  rO   r  r]  r<   r  r  r  r  )r  r  r  r   rd  re  r   rN   z! cancelOrders() does not support rf  rU  )r>  r[  r?  r  r   strr  'spotPrivatePostV1OrderOrdersBatchcancelrg  r)   r<   r  joinr  rH  rk  r  r  r  r  r  r  r  r  r  r  r  r  r/   r  parse_cancel_orders)r-  idsr]  rJ  r[  rK  rh  rM  r  r  r  r  rU  s                r/  cancel_orderszhtx.cancel_orders  s     !!![[(F
!??PVX^_
F	
 !..v7H/ZN!..v7IK[]klN%nc2,/5GK(+.GK(nc23A2BG./2@G./6+uv!II$++V]_eJfggH~'2^(^__!//8I?[N!//8JL\^lmN%&)hhsm
#-;)*6+uvh$*:$6!+1$<(&&vvyAG!%9M!NYYv'PQFh!
%)%G%GX^%_"
F)3);W*
+)-)a)abfbmbmnuw}b~)#+)-)^)^_c_j_jkrtz_{)|#|)-)Z)Z[_[f[fgnpv[w)x#x7*)-)f)fgkgrgrsz  }C  hD  *E  $E+)-)c)cdhdodopwy  eA  *B  $B)-)_)_`d`k`klsu{`|)}#}	"&>)-)[)[\`\g\ghoqw\x)y#y+)-)X)XY]YdYdelntYu)v#v)-)T)TUYU`U`ahjpUq)r#rH%)-)[)[\`\g\ghoqw\x)y#y+)-)X)XY]YdYdelntYu)v#v)-)T)TUYU`U`ahjpUq)r#r"477-P#PS]#]`j#jkkh ~~h/''--Q 	"> h0 $@#|#x $E $B#} $z#v#r $z#v#rs   Q%P?CQ%+Q,DQ% Q,Q%-Q.*Q%Q2Q%Q,Q%8Q9*Q%#Q$7Q%Q+Q%Q)Q%1Q20Q%"Q#+Q%Q!)Q%8Q#9AQ%Q%Q%Q%Q%Q%Q%Q%Q%Q%Q%Q%!Q%#Q%c                    | j                  |d      }d }||j                  d      }n| j                  |dg       }| j                  |ddg       }g }t	        dt        |            D ]+  }||   }|j                  | j                  ||dd             - t	        dt        |            D ]M  }||   }|j                  | j                  || j                  |d	d
      d| j                  |d      d             O |S )N	successesr  r  r  failedr   rK  )r=  r<   r   r6  r7  ra  )r=  r<   r   r  )	rA  r  r  r  rl  rm  r  rp  r  )r-  r  r  r  r  rp  rq  rD  s           r/  r  zhtx.parse_cancel_orders  s   : $$V[9	 ooc*GnnVY;G!!&(HbAq#g,' 	AAJEMM$//$+  	 q#f+& 	A1IEMM$//((
JG"!%!1!1%9J!K	+  	 r0  c                 4	  K   | j                          d{    d}|| j                  |      }d}| j                  d||      \  }}i }d}|dk(  rY||d   |d<   | j                  | j	                  ||             d{   }| j                  |d      }| j                  d|i      gS |t        | j                  dz         |d	   r|d
   |d<   |d   |d<   | j                  |dd      }| j                  |d      }	| j                  |dd      }
| j                  |g d      }|d   rd}| j                  d|      \  }}|dn|}|dk(  r|r+| j                  | j	                  ||             d{   }n|	r+| j                  | j	                  ||             d{   }n|
r+| j!                  | j	                  ||             d{   }no| j#                  | j	                  ||             d{   }nD|dk(  r>|r+| j%                  | j	                  ||             d{   }n|	r+| j'                  | j	                  ||             d{   }n|
r+| j)                  | j	                  ||             d{   }n| j+                  | j	                  ||             d{   }n|d   rh|d   r|r+| j-                  | j	                  ||             d{   }nT|	r+| j/                  | j	                  ||             d{   }n'|
r*| j1                  | j	                  ||             d{   }n| j3                  | j	                  ||             d{   }n|d	   r|r*| j5                  | j	                  ||             d{   }n|	r*| j7                  | j	                  ||             d{   }nt|
r*| j9                  | j	                  ||             d{   }nH| j;                  | j	                  ||             d{   }nt=        | j                  dz   |z   dz         | j                  |d      }| j?                  |      S 7 P7 7 7 7 7 }7 M7 #7 7 7 7 r7 H7 !7 7 7 7 vw)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>`
        NrT   rL   r<   r]  rU  r=  z- cancelAllOrders() requires a symbol argumentrO   r  r  r  r  r  r  Fr  r   rd  re  r   rN   z$ cancelAllOrders() does not support rf  ) r>  r[  r?  1spotPrivatePostV1OrderOrdersBatchCancelOpenOrdersrg  r  rp  r)   r<   r  rH  r  r  rk  6contractPrivatePostLinearSwapApiV1SwapTriggerCancelall3contractPrivatePostLinearSwapApiV1SwapTpslCancelall4contractPrivatePostLinearSwapApiV1SwapTrackCancelall/contractPrivatePostLinearSwapApiV1SwapCancelall;contractPrivatePostLinearSwapApiV1SwapCrossTriggerCancelall8contractPrivatePostLinearSwapApiV1SwapCrossTpslCancelall9contractPrivatePostLinearSwapApiV1SwapCrossTrackCancelall4contractPrivatePostLinearSwapApiV1SwapCrossCancelall0contractPrivatePostSwapApiV1SwapTriggerCancelall-contractPrivatePostSwapApiV1SwapTpslCancelall.contractPrivatePostSwapApiV1SwapTrackCancelall)contractPrivatePostSwapApiV1SwapCancelall0contractPrivatePostApiV1ContractTriggerCancelall-contractPrivatePostApiV1ContractTpslCancelall.contractPrivatePostApiV1ContractTrackCancelall)contractPrivatePostApiV1ContractCancelallr/   r  )r-  r]  rJ  r[  rK  rh  rM  rU  r  r  r  r  s               r/  cancel_all_orderszhtx.cancel_all_orders  s     !!![[(F
!??@QSY[ab
F
 !$*4L!!SSTXT_T_`gioTpqqH >>(F3DD!   ~'2a(abbh$*:$6!'-d|GO$&&vvyAG!%9M!N~~fj%@HYYv'\]Fh!
%)%G%GHY[a%b"
F)3);W*
+)-)d)deiepepqx  {A  fB  *C  $C+)-)a)abfbmbmnuw}b~)#!)-)b)bcgcncnovx~c  *A  $A)-)])]^b^i^ijqsy^z){#{7*)-)i)ijnjujuv}  @F  kG  *H  $H+)-)f)fgkgrgrsz  }C  hD  *E  $E!)-)g)ghlhshst{  ~D  iE  *F  $F)-)b)bcgcncnovx~c  *A  $A	"&>)-)^)^_c_j_jkrtz_{)|#|+)-)[)[\`\g\ghoqw\x)y#y!)-)\)\]a]h]hiprx]y)z#z)-)W)WX\XcXcdkmsXt)u#uH%)-)^)^_c_j_jkrtz_{)|#|+)-)[)[\`\g\ghoqw\x)y#y!)-)\)\]a]h]hiprx]y)z#z)-)W)WX\XcXcdkmsXt)u#u"477-S#SV`#`cm#mnn >>(F3D++D11S 	"0 rB $C# $A#{ $H $E $F $A $}#y#z#u $}#y#z#usD  RQ&A(R?Q) C3R3Q,4,R Q/!,RQ2*R8Q592R+Q8,,RQ;,RQ>*R0R17R(R),RR,RR
)R,R-0RR+R	R
+R5R6)RR AR)R,R/R2R5R8R;R>RRRR
RRRRRRr  c                    K   | j                          d{    d|dkD  r| j                  |dz        ndi}| j                  | j                  ||             d{   }|S 7 L7 w)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
        Nr  r   r  )r>  r  %v2PrivatePostAlgoOrdersCancelAllAfterrg  )r-  r  rJ  rh  rM  s        r/  cancel_all_orders_afterzhtx.cancel_all_orders_after>  sr      !!!Wq[t((48q
 CCDKKPWY_D`aa  	" bs"   A'A#AA'A%A'%A'rB  c                 P   | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |       |||| j	                  |      ||dS )Naddress
addressTagrB  noter  )rB  r  tagr  r  r=  )rA  r  r  check_addressr  )	r-  depositAddressrB  r  r  r  r  r  r  s	            r/  parse_deposit_addresszhtx.parse_deposit_addressY  s     "">9=~|<%%njA
%%j(;&&z8<7$$^W=	7#..y9"
 	
r0  r  c                 <  K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |dg       }| j                  ||d   gd      }| j                  |d      S 7 7 Bw)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
        NrB  r<   rU  r  Fr  )r>  rB  %spotPrivateGetV2AccountDepositAddressrg  rH  parse_deposit_addressesindex_by)r-  r  rJ  rB  rh  rM  rU  parseds           r/  "fetch_deposit_addresses_by_networkz&htx.fetch_deposit_addresses_by_networks  s      !!!==&
 CCDKKPWY_D`aa x4--dXf5E4FN}}VY//+ 	"
 bs#   BBA BBABBc                    K   | j                          d{    | j                  |      }| j                  |      \  }}| j                  ||       d{   }| j	                  |d   ||      }||   S 7 ^7 !w)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>`
        Nr  )r>  rB  handle_network_code_and_paramsr  )select_network_code_from_unified_networks)r-  r  rJ  rB  r  paramsOmitedindexedAddressesselectedNetworkCodes           r/  fetch_deposit_addresszhtx.fetch_deposit_address  s      !!!==&$($G$G$O!\!%!H!H|!\\"LLXV\M]_jl|} 344 	" ]s!   A9A5>A9A7 A97A9c                   K   | j                          d {    | j                  |      }d|d   i}| j                  | j                  ||             d {   }| j	                  |dg       }| j                  ||d   gd      }	g }
t        dt        |	            D ]:  }|	|   }|d u xs |d   |k(  }|d u xs |d   |k(  }|s'|s*|
j                  |       < |
S 7 7 w)	NrB  r<   rU  r  Fr   r  r  )	r>  rB  &spotPrivateGetV2AccountWithdrawAddressrg  rH  r  rl  rm  r  )r-  r  r  r  rJ  rB  rh  rM  rU  allAddresses	addressesrq  r  	noteMatchnetworkMatchs                  r/  fetch_withdraw_addresseszhtx.fetch_withdraw_addresses  s    !!!==&
 DDT[[QXZ`Eabb x433D8F;K:LeT	q#l+, 	*A"1oGC76?d+BI'4/WWY5G;5VL\  )	* ; 	"
 cs/   C CA C CA+C C C C c                 ,  K   ||dkD  rd}| j                          d{    d}|| j                  |      }dddd}||d   |d<   |||d	<   | j                  | j                  ||             d{   }| j	                  |d
   |||      S 7 p7 w)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>`
        NrB   r  nextr   rT  directr  r<   rB  r]  rU  r>  rB  $spotPrivateGetV1QueryDepositWithdrawrg  parse_transactionsr-  r  rT  r  rJ  rB  rh  rM  s           r/  fetch_depositszhtx.fetch_deposits  s      =ECKE!!!}}T*H

 "*4.GJ#GFOBB4;;wX^C_``6 &&x'75%PPQ 	" a"   BBAB4B5BBc                 ,  K   ||dkD  rd}| j                          d{    d}|| j                  |      }dddd}||d   |d<   |||d	<   | j                  | j                  ||             d{   }| j	                  |d
   |||      S 7 p7 w)a2  
        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>`
        NrB   r   r,  r   r-  r<   rB  r]  rU  r/  r2  s           r/  fetch_withdrawalszhtx.fetch_withdrawals  s      =ECKE!!!}}T*H

 "*4.GJ#GFOBB4;;wX^C_``2 &&x'75%PPM 	" ar4  transactionc                 V   | j                  |d      }| j                  | j                  |d            }| j                  |d      }|dk(  rd}| j                  |d      }|t        j                  |      }| j                  |d      }| j                  |d      }|d	k(  r|j                  d
      dk  rd
|z   }| j                  |d      }	|	dk(  }
i d|d| j                  |dd      d|d|d| j                  |      d| j                  |      d| j                  |d      dd dd d| j                  |d      dd dd d|d| j                  |d      d|d| j                  | j                  |d            d| j                  |d       d |
|| j                  |      d d!d"S )#Nr4  rB  rT  r   
withdrawalrZ  r  ztx-hashr  0xr   zsub-typeFASTr=  r<   rU  txidr  rQ  r  r  	addressToaddressFromr  zaddress-tagtagTotagFromrw  r   r  r;  z
updated-at)rB  r}  rate)commentinternalrZ  )r  r  rA  r7   
string_absro  r  r  r  ra  parse_transaction_statusr,  )r-  r7  rB  r  r  rT  rN  r  txHashr3  rC  s              r/  parse_transactionzhtx.parse_transaction3  sD   f %%k<@	&&t'7'7Z'PQV4:D"";6((1G$$[':	!!+y9&++d"3a"7F]F"";
;f$
K
$$$[$?
 F
 	

 Y/
 t..y9
 t''Y?
 
 4
 4##K?
 T
 t
 D
 d&&{H=
 
  d33D4D4D[RY4Z[!
" t((lC#
$   ))'2)
 	
r0  c                 L    dddddddddddddddd}| j                  |||      S )Nr  pendingr4  rK  )unknown
confirming	confirmedsafeorphanrO  rK  	reexaminerejectpasszwallet-rejectzconfirm-errorrepealedzwallet-transferzpre-transferrW  rX  s      r/  rE  zhtx.parse_transaction_status  sO      #"""%% (%%
( &&99r0  r  c                   K   | j                  ||      \  }}| j                          d{    | j                  |       | j                  |      }||d   j	                         d}|||d<   d}| j                  |      \  }}|| j                  ||      |d<   t        | j                  |||            }| j                  | j                  di       }	| j                  |	dd      r| j                  |d	      }
|
{| j                          d{   }| j                  | j                  |      | _        | j                  |d
   |i       }| j                  |d	      }
|
t!        | j"                  dz         | j                  ||
|      }| j%                  |d	      }| j'                  |      }t)        j*                  ||      }t        |      }t        |      |d	<   t        | j                  |||            }||d<   | j-                  | j/                  ||             d{   }| j1                  ||      S 7 7 ,7 w)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>`
        Nr<   )r  rB  zaddr-tagr  r   r  FrZ  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" parameterrw  )handle_withdraw_tag_and_paramsr>  r  rB  r  r  r  floatcurrency_to_precisionrH  r  r  ra  r  r(  
currenciesr)   r<   r  r  r7   
string_sub$spotPrivatePostV1DwWithdrawApiCreaterg  rG  )r-  r  rw  r  r  rJ  rB  rh  r  withdrawOptionsrZ  rW  targetNetwork	feeStringrL  amountSubtractedStringamountSubtractedrM  s                     r/  r   zhtx.withdraw  sI     99#vFV!!!7#==& ,,.
 ?"%GJ"AA&IV"#66{DIGGt11$LM//$,,
BG>>/<?""651C{#'#8#8#::
"&"2"24??J"O $0DkSU V&&}e<;+DGG  7Y  -Y  Z  Z224kJIYYvu-F008L%,%7%7i%P"$%;<"9-GEN455d<LkZ[F"BB4;;wX^C_`` %%h99Q 	"$ ; as5   )IH9C$IH<DI"H?#I<I?Ir   c           
      b    | j                  |d      }| j                  d |      }||d d |d d d d d	S )NrU  )	r=  r<   r  rQ  rB  rw  fromAccount	toAccountr   )rA  r  )r-  r   rB  r<   r  s        r/  parse_transferzhtx.parse_transfer  sM     h/&&tX6

 
	
r0  r`  ra  c                   K   | j                          d{    | j                  |      }|d   t        | j                  ||            d}d}| j	                  dd|      \  }}| j                  |      }	| j                  |      }
|
dk(  }|	dk(  }| j                  |
| j                        }| j                  |	| j                        }|	dk(  }|
dk(  }|r#|r!t        | j                  dz   |z   dz   |z         |	d	k(  xs |
d	k(  }d}|rK|	d
z   |
z   }| j                  |d|      }||d<   | j                  | j                  ||             d{   }nT|r-|r+| j                  | j                  ||             d{   }n%|r,|r*| j                  | j                  ||             d{   }n|r1|r/|
|d<   | j                  | j                  ||             d{   }n|r1|r/|	|d<   | j!                  | j                  ||             d{   }n|dk(  rQ|	dk(  s|dk(  rd}	nd}
| j                  |d      }| j#                  |d      }|| j%                  |      }||d<   nd|d<   |rdn|	|d<   |rdn|
|d<   | j'                  | j                  ||             d{   }| j)                  ||      S 7 7 p7 D7 7 7 7 &w)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>`
        Nr<   rB  rw  r   rd  rI   z+ transfer() cannot make a transfer between z and r  z-to-rT  r]  r   rN   zlinear-swapzmargin-accountr  rL   r  r  )r>  rB  rU  rV  r  convert_type_to_accountin_arrayr  r*   r<   rA   spotPrivatePostV1FuturesTransferrg   privatePostCrossMarginTransferIn!privatePostCrossMarginTransferOutprivatePostDwTransferInMarginprivatePostDwTransferOutMarginr  ro  v2PrivatePostAccountTransferrb  )r-  r  rw  r`  ra  rJ  rB  rh  r3  fromAccountIdtoAccountIdtoCross	fromCross
toIsolatedfromIsolatedfromSpottoSpotfromOrToFuturesAccountrM  rT  r]  s                        r/  r   zhtx.transfer  s    * !!!==& D66tVDE
 99*dFS44[A229=(!W,	]];9
}}]DHH= E)%TWW'TTWbbelloxxyy"/9"<![+QZBZ! 6)K7D##FFD9D"GFO!BB4;;wX^C_``H'!BB4;;wX^C_``H6!CCDKKPWY_D`aaH* +GH!??GU[@\]]Hf -GH!@@WV\A]^^H("!V+1M$1M"/K))&(;684%!^^F3F06G,-06G,-(0fmGFO&,F+GDM!>>t{{7TZ?[\\H ""8X66{ 	"0 a`a ^ _" ]s}   KJ9D5KJ<.K;J?<.K*K+2KK2KKBK"K	#K<K?KKKK	Kc                    K   | j                          d{    | j                  |       d{   }| j                  |dg       }| j                  |      S 7 A7 *w)ax  
        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>`
        NrU  )r>  spotPrivateGetV1MarginLoanInforH  parse_isolated_borrow_ratesr  s       r/  fetch_isolated_borrow_rateszhtx.fetch_isolated_borrow_ratesI  s\      !!!<<VDD< x4//55A 	"Ds   AAAA)AAr=  c           
         | j                  |d      }| j                  ||      }| j                  |dg       }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	|| j                  |      | j	                  |d      | j                  |	      | j	                  |d      dd d |d	S )	Nr]  rW  r   r   rB  zactual-ratei \&)	r]  r  baseRater  	quoteRater  r  rQ  r=  )rA  r`  rH  r  ra  )
r-  r=  r[  rb  r]  rW  baseData	quoteDatar  r  s
             r/  parse_isolated_borrow_ratezhtx.parse_isolated_borrow_ratet  s    0 ##D(3!!(F3__T<<
??:q1OOJ2	!!(J7""9j9++F3((=A,,W5)))]C

 
	
r0  c                   K   |t        | j                  dz         d}| j                  |dd      \  }}|r!| j                  d||||dddd		       d{   S | j	                          d{    | j                  |      }d
|d   i}d}|d   r*| j                  | j                  ||             d{   }nG|d   r*| j                  | j                  ||             d{   }nt        | j                  dz         | j                  |d      }	| j                  |	d      }
| j                  |	dg       }g }t        dt        |            D ]w  }||   }|
|d<   | j                  |d
      }| j                  |      }| j                  |d      }|j!                  ||| j#                  |d      || j%                  |      d       y | j'                  |d      }| j)                  ||d   ||      S 7 7 7 D7 w)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~   r\  
page_indexcurrent_pager   r   r  r<   r   r   zA fetchFundingRateHistory() supports inverse and linear swaps onlyrU  r   funding_timefunding_rate)r=  r]  fundingRater  rQ  r  r]  )r)   r<   r  fetch_paginated_call_cursorr>  r[  3contractPublicGetSwapApiV1SwapHistoricalFundingRaterg  9contractPublicGetLinearSwapApiV1SwapHistoricalFundingRater/   rH  rl  rm  rA  r`  r  r  ra  r  rv  rw  )r-  r]  rT  r  rJ  r\  r[  rh  rM  rU  cursorrp  ratesrq  r$  rb  symbolInnerr  sorteds                      r/  fetch_funding_rate_historyzhtx.fetch_funding_rate_history  s>     >#DGG.e$eff88AZ\fg&99:SU[]bdikqs  BP  RS  UW  X  X  X!!!V$VD\
 )!UUVZVaVabikqVrssHH![[\`\g\ghoqw\xyyHtww)llmm. x0~6vr2q#f+& 	A1IE$*E.!''?H**84K))%@ILL%#//~F& LL3 	 e[1009I5RWXXk X! tysJ   AG=G1G=+G4,AG=3G74.G="G:#DG=4G=7G=:G=c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t        j                  ||      }| j                  |d      }	| j                  |	|      }
i d|d|
dd dd d	d d
d dd dd d| j                  |d      d|d| j                  |      d|d|d| j                  |      dd dd dd d| j                  |      iS )Nestimated_rater  next_funding_timer  r=  r]  	markPrice
indexPriceinterestRateestimatedSettlePricer  rQ  r  r  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)ra  r  rA  r7   rX  r`  r  parse_funding_interval)r-  r   r[  r  r  r  fundingTimeStringnextFundingTimeStringmillisecondsIntervalrb  r]  s              r/  parse_funding_ratezhtx.parse_funding_rate  s     **85EF,,X~F#00;NO ,,X~F $ 0 0;N O&112GIZ[##Ho>!!(F3
H
f
 
 $	

 D
 #D
 
 
 4++HnE
  0
 t||,<=
 
 #$8
 "4<<0D#E
 "4
  '!
" &t#
$ 334HI%
 	
r0  c                 8    dddddd}| j                  |||      S )Nr   r   8h16h24h)360000014400000288000005760000086400000rW  )r-  r  	intervalss      r/  r  zhtx.parse_funding_interval  s/    
	 	8X>>r0  c                   K   | j                          d{    | j                  |      }d|d   i}d}|d   r*| j                  | j                  ||             d{   }nG|d   r*| j	                  | j                  ||             d{   }nt        | j                  dz         | j                  |di       }| j                  ||      S 7 7 s7 Fw)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>`
        Nr  r<   r   r   z: fetchFundingRate() supports inverse and linear swaps onlyrU  )	r>  r[  )contractPublicGetSwapApiV1SwapFundingRaterg  /contractPublicGetLinearSwapApiV1SwapFundingRater/   r<   rH  r  )r-  r]  rJ  r[  rh  rM  rp  s          r/  fetch_funding_ratezhtx.fetch_funding_rate   s      !!!V$VD\
 )!KKDKKX_agLhiiHH!QQRVR]R]^egmRnooHtww)eeff  626&&vv669 	" jos5   CCACC.CCACCCc                 t  K   | j                          d{    | j                  |      }| j                  | j                  dd      }d}| j	                  |dd|      \  }}|.| j                  |d      }| j                  |      }|d   }|rdnd}i }d}	|dk(  r*| j                  | j                  ||             d{   }	nG|dk(  r*| j                  | j                  ||             d{   }	nt        | j                  dz         | j                  |	d	g       }
| j                  |
|      S 7 7 t7 Gw)
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
        Nr  r   r   r3  r   r   z1 fetchFundingRates() not support self market typerU  )r>  r  rA  r  r  r[  4contractPublicGetLinearSwapApiV1SwapBatchFundingRaterg  .contractPublicGetSwapApiV1SwapBatchFundingRater/   r<   rH  parse_funding_rates)r-  re  rJ  r  r3  firstSymbolr[  isLinearrh  rM  rU  s              r/  fetch_funding_rateszhtx.fetch_funding_ratesI  sO     !!!%%g.))$,,8H(S77@SU^`no**7A6K[[-Fh'H"*h	G
 h!VVW[WbWbcjlrWsttH	!!PPQUQ\Q\]dflQmnnHtww)\\]]& x4''g66O 	" uns5   D8D1B(D8?D4 .D8.D6/AD84D86D8c                 T  K   | j                          d{    d}| j                  d|      \  }}|dn|}i }|| j                  |      |d<   |||d<   d}d}	|dk(  rE|| j                  |      }|d   |d<   | j	                  | j                  ||             d{   }	nD|| j                  |      }
|
d   |d	<   | j                  | j                  ||             d{   }	| j                  |	d
      }| j                  ||      }| j                  ||||      S 7 7 7 Aw)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>`
        Nrk   rd  z
start-dater]  re  r<   r]  rB  rU  )r>  rk  yyyymmddr[  privateGetMarginLoanOrdersrg  rB  privateGetCrossMarginLoanOrdersrH  parse_borrow_interestsfilter_by_currency_since_limit)r-  r  r]  rT  r  rJ  r  rh  r[  rM  rB  rU  interests                r/  fetch_borrow_interestzhtx.fetch_borrow_interest}  sT     !!!
!??@UW]^
F!+!3W*
$(MM%$8GL!#GFO#!V,$*4L!!<<T[[RX=YZZH==.&.tn
#!AA$++gW]B^__H. x0..tV<228T5%PP[ 	" [
 `s5   D(D!BD(D$ AD($D&%=D($D(&D(c                 p   | j                  |d      }|dnd}| j                  |      }| j                  |d      }| j                  |d      }||| j                  | j                  |d            | j	                  |d      | j	                  |d      | j	                  |d      ||| j                  |      d		S )
Nr]  rd  re  z
accrued-atrB  zinterest-amountzinterest-ratezloan-amount)	r=  r]  rB  r  r  amountBorrowedr  r  rQ  )rA  r#  r  r  ra  r  )r-  r=  r[  rb  r  r]  r  s          r/  parse_borrow_interestzhtx.parse_borrow_interest  s    T ##D(3!)!1W

!!(+!!&(3%%dL9	//0@0@z0RS((/@A ,,T?C"..t]C$"Y/

 
	
r0  c                 B    | j                         | j                  d   z
  S )Nr  )millisecondsr  )r-  s    r/  r+  z	htx.nonce  s       "T\\2B%CCCr0  r   r  c                 
   d}| j                  || j                  |            }t        |t              r|dk(  s|dk(  r|| j                  z  }n|dk(  s|dk(  r|dz  }|d| j                  ||      z   z  }|dk(  s|dk(  r%| j                          | j                  | j                         d      }	dd	| j                  |	d
}
|dk7  r| j                  |
|      }
| j                  |
      }| j                  |d      }dj                  || j                  ||g      }| j                  | j!                  |      | j!                  | j"                        t$        j&                  d      }|d| j                  d|i      z   z  }|d|z   z  }|dk(  r| j)                  |      }ddi}nddi}n|r|d| j                  |      z   z  }| j                  | j*                  d   |   d| j                  i      |z   }n| j-                  |d      }| j-                  |d      }| j-                  |d      }| j-                  |d      }d }| j/                  | j*                  d   |      }t        |t              s6| j/                  ||      }t        |t              s|| j/                  ||      }|}|| j                  ||      z  }|dk(  r|r|d| j                  |      z   z  }n |dk(  r| j                          |dk(  r| j/                  | j0                  di       }| j-                  |dd      }|j3                  d      d k(  r+|j5                  d!      r| j-                  |d"      }|A||d"<   n;|j5                  d#      r*| j-                  |d$      }||| j7                         z   |d$<   | j                  | j                         d      }	dd	| j                  |	d
}
| j                  |
      }
|dk7  r#| j                  |      }| j                  |
|      }
| j                  |
d      j9                  d%d&      }dj                  ||||g      }| j                  | j!                  |      | j!                  | j"                        t$        j&                  d      }|d| j                  d|i      z   z  }|d|z   z  }|dk(  r&| j)                  |      }t;        |      dk(  rd'}ddi}nddi}| j                  | j*                  d   |   d|i      |z   }||||d(S ))Nr  r   r   r   r   v2T
HmacSHA256rP  )SignatureMethodSignatureVersionAccessKeyId	TimestampPOSTT
base64&	Signature?zContent-Typezapplication/jsonz!application/x-www-form-urlencodedr   rH   r   r   r  r  r   r  r<   r  cancelrD  r  zorders/placera  z%2cz%2Cz{})r   r  bodyheaders)r  extract_paramsr   r  rF   implode_paramscheck_required_credentialsymdhmsr+  apiKeyrg  keysort	urlencoder  rH   hmacencodesecrethashlibsha256r  r   rA  rH  r  ro  endswithr  r  rm  )r-  pathr   r  rJ  r  r  r   queryr  rh  sortedRequestauthpayload	signaturerT  accesslevelOneNestedPathlevelTwoNestedPathrH   r   r  r<   channelCoder  sortedQuerys                             r/  signzhtx.sign  s   		&$"5"5d";<c3xSI%5t||##);t3,,T6:::Ci3+#5//1 KK

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

c:	'3(+#';;!*	! ,,w/V#"&,,u"5K"kk';?G~~gt4<<UEJ))VXsD$AB IIdkk'&:DKK<TV]VdVdfno	dnnk9-EFFFsTz!V#99U+D4yA~#&(:G
 '(KG %%dii&6t&<H? C fdwOOr0  httpCodereasonr   r  r  r  c
                 r   |y d|v r| j                  |d      }
|
dk(  r| j                  |dd      }| j                  dz   |z   }| j                  | j                  d   ||       | j                  | j                  d   ||       | j                  |dd	      }| j                  | j                  d   ||       t        |      d
|v rD| j                  dz   |z   }| j                  |d
      }| j                  | j                  d   ||       | j                  |d      }| j                  |d      }|| j                  |d      }| j                  |d      }| j                  |d	      }| j                  dz   |z   }| j                  | j                  d   ||       | j                  | j                  d   ||       y )Nr   errorr]  r\  r  r  r  zerr-msgerr_msgr  rU  r  r   )	rA  r  r<   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr%   r  r  )r-  r  r  r   r  r  r  rM  requestHeadersrequestBodyr   r  feedbackmessagerU  
errorsListri  errcode
errmessagefeedBacks                       r/  handle_errorszhtx.handle_errorsf  s   x
 %%h9F ))(J
K77S=4/44T__W5MtU]^44T__W5MtU]^,,Xy)L44T__W5MwX`a#H--Xww}t+H##Hf5D001I4QYZ~~h/^^D(3
!NN:q1E&&uj9G))%;Jww}t+H001I7T\]001I:W_`r0  c                   K   | j                          d{    | j                  |      }| j                  d||      \  }}ddi}|||d<   d}	|dk(  r|d   |d<   |d	   r]d}
| j                  d|      \  }
}|
d
n|
}
|
dk(  r	|d   |d<   n|d   |d<   | j	                  | j                  ||             d{   }	n[| j                  | j                  ||             d{   }	n1|d   |d<   | j                  | j                  ||             d{   }	| j                  |	dg       }| j                  ||||      S 7 *7 7 b7 2w)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>`
        Nr|   rT  z30,31
start_daterN   r<   r   r   rd  re  mar_acctr  r]  rU  )
r>  r[  r?  rk  :contractPrivatePostLinearSwapApiV3SwapFinancialRecordExactrg  4contractPrivatePostSwapApiV3SwapFinancialRecordExact4contractPrivatePostApiV3ContractFinancialRecordExactr  parse_incomes)r-  r]  rT  r  rJ  r[  rK  r  rh  rM  r  rU  s               r/  fetch_funding_historyzhtx.fetch_funding_history  s     !!!V$ >>?TV\^de
EG
 $)GL!"(,GJh. "
%)%G%GH]_e%f"
F)3);W*
+*0,GJ'*0*;GJ'!%!`!`aealalmtv{a|!}}, "&!Z!Z[_[f[fgnpu[v!ww &tGH!VVW[WbWbcjlqWrssH~~h3!!$u==I 	"R ~, x tsF   E	E B!E	8E9)E	"E#1E	E,E	E	E	E	r  c                 8  K   |t        | j                  dz         | j                          d{    | j                  |      }| j	                  d||      \  }}d|i}|dk(  r|d   r	|d   |d<   n|d	   |d
<   d}|d   rd}	| j                  d|      \  }	}|	dn|	}	|	dk(  r+| j                  | j                  ||             d{   }|S |	dk(  r+| j                  | j                  ||             d{   }|S t        | j                  dz         |dk(  r+| j                  | j                  ||             d{   }|S |dk(  r+| j                  | j                  ||             d{   }|S t        | j                  dz         7 _7 7 7 U7 'w)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  rO   r   r  r]  r<   r  r   rd  re  + setLeverage() not support self market typerN   )r)   r<   r>  r[  r?  rk  5contractPrivatePostLinearSwapApiV1SwapSwitchLeverRaterg  :contractPrivatePostLinearSwapApiV1SwapCrossSwitchLeverRater/   /contractPrivatePostApiV1ContractSwitchLeverRate/contractPrivatePostSwapApiV1SwapSwitchLeverRate)
r-  r  r]  rJ  r[  rK  r  rh  rM  r  s
             r/  set_leveragezhtx.set_leverage  s     >#DGG.Y$YZZ!!!V$ >>}fV\]
E(
 !fY&7 &z 2GH'-d|GO$(J!%!C!CMSY!ZJ%/%7jJZ'!%![![\`\g\ghoqv\w!xxN M w&!%!`!`aealalmtv{a|!}}J G #477-Z#Z[[ X%!%!U!UVZVaVabikpVq!rr* ) v%!%!U!UVZVaVabikpVq!rr& # #477-Z#Z[[M 	"  y}  srsY   .FFBFF	/F8F9AF F/F0F1FFFFFc                 0   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |dd      }| j                  |      }	|||	|| j                  |      ||dS )Nr  rw  r6  r<   r]  asset)r=  r]  r  r  rQ  r<   rw  )rA  r`  ra  r  r  r  r  )
r-  incomer[  rb  r]  rw  r  r<   r  r  s
             r/  parse_incomezhtx.parse_income$  s     ##FO<!!(F3!!&(3%%fd3	fd+'''B
&&z2"Y/
 	
r0  positionc                    | j                  | j                  |d            }|d   }| j                  |d      }| j                  |d      }| j                  |      }| j	                  |d      }| j                  |d      }| j                  |d      }	|	dk(  rd	nd
}
| j	                  |d      }| j                  |d      }| j                  |d      }t        j                  | j                  |d      d      }| j                  |d      }t        j                  ||      }d }|d   rt        j                  ||      }nt        j                  ||      }d}t        j                  ||      }| j                  |d      }| j	                  |d      }| j                  |d      }t        j                  ||      }t        j                  ||      }t        j                  ||      }| j                  i d|dd d|d| j                  |      d|d|d| j                  |      d|
d|d| j                  |      d| j                  |      d|d | j                  |      d!d d"d d#|d$| j                  |      | j                  |      | j                  |      | j                  |      | j                  |      d d d d d d d%
      S )&Nr  r]  rc  r  	cost_openposition_marginr!  ru  longshortprofit_unrealmargin_moder  profit_rater  
last_pricer   rd  r  liquidation_priceadjust_factorr=  r<   	contracts
entryPrice
collateralr"  unrealizedPnlr  r   r  notionalr  	lastPriceliquidationPriceinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior  rQ  r  lastUpdateTimestampr
  r  )
r#  rA  rH  r  ra  r7   r  r  safe_positionr,  )r-  r  r[  r]  r  r  contractSizeStringr   r&  rawSider"  unrealizedProfitr  r  r   r$  	faceValuer#  intialMarginPercentager!  r%  adjustmentFactorr)  r(  r*  s                            r/  parse_positionzhtx.parse_position@  sV   @ !!$"2"28_"MN!$$Xx8	v~>!22<@%%h<
((3DE""8[9!U*v++HoF%%h>
##Hl;''(8(8=(QSXY
$$X|<	&&y2DE	()))Y?H)))Y?H J!(!3!3M8!L%%h0@A
++H6IJ++HoF&-&8&89I8&T##../JHU(():JG!! #
H#
$#
 f#
 **95	#

 L#
 *#
 $++J7#
 D#
 -#
 ))(3#
 $++J7#
 *#
 ))(3#
 #
 #
   0!#
" T..}=##
$ (,'8'89O'P!%!2!23D!E+/+<+<=X+Y,,[9#'!#7#
  	r0  c           
      &  K   | j                          d{    | j                  |      }d}|3t        |      }|dkD  r#| j                  |d      }| j	                  |      }d}| j                  d|d      \  }}d}| j                  d||d      \  }}d}| j                  d||      \  }}|dk(  rd}d}	|dk(  rV|dk(  r| j                  |       d{   }	n|dk(  r| j                  |       d{   }	nnt        | j                  d	z         |dk(  r| j                  |       d{   }	n7|d
k(  r| j                  |       d{   }	nt        | j                  d	z         | j                  |	dg       }
| j                  |	d      }g }t!        dt        |
            D ]K  }|
|   }| j#                  |      }|j%                  | j'                  ||| j)                  |      d             M | j+                  |d|d      S 7 7 47 7 7 ƭw)au  
        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   rd  r   rL   rO   re  z. fetchPositions() not support self market typerN   rU  r6  r  rQ  r]  F)r>  r  rm  rA  r[  rk  r  r?  2contractPrivatePostLinearSwapApiV1SwapPositionInfo7contractPrivatePostLinearSwapApiV1SwapCrossPositionInfor/   r<   ,contractPrivatePostApiV1ContractPositionInfo,contractPrivatePostSwapApiV1SwapPositionInforH  r  rl  r3  r  rg  r  filter_by_array_positions)r-  re  rJ  r[  symbolsLengthri  r  r3  rK  rM  rU  r  rp  rq  r  r  s                   r/  fetch_positionszhtx.fetch_positions  sB      !!!%%g.LMq ((!4U+
!??@PRXZab
F99:JFTZ\de
!??@PRXZ`a
F!JhZ'!%!X!XY_!``w&!%!]!]^d!ee"477-]#]^^: X%!%!R!RSY!ZZv%!%!R!RSY!ZZ"477-]#]^^f x4%%h5	q#d)$ 	AAwH((2FMM$++f& LL3/  	 --fhOOm 	"& ae@ [ZsY   HHB<HHH2H
36H)H*HH	B<HH
HHHc                   K   | j                          d{    | j                  |      }d}| j                  d|      \  }}|dn|}| j                  d||      \  }}i }|d   r|d   r	|d   |d<   n|dk(  rd|d	<   |d
   |d<   d}|d   rv|dk(  r*| j	                  | j                  ||             d{   }n|dk(  r*| j                  | j                  ||             d{   }nt        | j                  dz         |dk(  r*| j                  | j                  ||             d{   }nG|dk(  r*| j                  | j                  ||             d{   }nt        | j                  dz         | j                  |d      }	d}
|dk(  r|	}
n| j                  |	d      }
| j                  |
dg      }| j                  |
d      }d}|d   r4|d   r/t        dt        |            D ]  }||   }|d   |d
   k(  s|} n n| j                  |d      }| j                  |d      }| j!                  | j                  ||            }||d<   | j#                  |      |d<   |S 7 Q7 7 7 D7 w)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   rd  rO   r   r  r]  r  r  r<   r  r   re  z- fetchPosition() not support self market typerN   r	  rU  r   	positionsr6  r  rQ  )r>  r[  rk  r?  9contractPrivatePostLinearSwapApiV1SwapAccountPositionInforg  >contractPrivatePostLinearSwapApiV1SwapCrossAccountPositionInfor/   r<   3contractPrivatePostApiV1ContractAccountPositionInfo3contractPrivatePostSwapApiV1SwapAccountPositionInforH  r  rl  rm  r  r3  r  )r-  r]  rJ  r[  r  rK  r  rh  rM  rU  r  omittedr>  r  rq  r$  r  r  s                     r/  fetch_positionzhtx.fetch_position"  s     !!!V$
!??QWX
F!+!3W*
 >>PVX^_
E(y 1 &z 2GHW$,2()'-d|GO$(Z'!%!_!_`d`k`klsuz`{!||w&!%!d!deiepepqxz  fA  "B  B"477-\#\]]n X%!%!Y!YZ^ZeZefmotZu!vvv%!%!Y!YZ^ZeZefmotZu!vv"477-Z#Z[[L x0 GoodA.G))Gk]3OOG[9	(y 11c)n- !!)VD\9$H	 y!4H%%h5	$$T[[7%CD'{!\\)4zW 	"  } Bt wvsa   I6I'BI66I*7.I6%I-&AI6,I0-.I6I3B$I6A'I6*I6-I60I63I6c                 J    ddddddddddddddd	}| j                  |||      S )
Nr2  rZ  r   creditr  r9  exchangerebate)r2  etfztransact-feezfee-deductionr   rF  liquidationr  r  r   zwithdraw-feerG  zother-typesrH  rW  )r-  rT  r  s      r/  parse_ledger_entry_typezhtx.parse_ledger_entry_type  sJ    !"""  $!"%
  tT22r0  itemc                    | j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  ||| j                  |d      |||| j                  |      || j                  |d      || j                  |      d d d d d|      S )	NrB  
transactIdtransferTypetransactTimer  r!  transactAmt)r=  r<   r!  r  referenceIdreferenceAccountrT  rB  rw  r  rQ  beforeafterr   rZ  )rA  r  r  r  safe_ledger_entryrK  ra  r  )	r-  rL  rB  r  r  r<   rO  r  r  s	            r/  parse_ledger_entryzhtx.parse_ledger_entry/  s     %%dJ7
&&z8<%%j(;dL1''n=%%dN;	""45%%))$< '00>&&t];"Y/'
  ! 	r0  c                   K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||d       d{   S | j                  ddd|       d{   }d|i}d}|| j	                  |      }|d   |d	<   |||d
<   |||d<   | j                  d||      \  }}| j                  | j                  ||             d{   }	| j                  |	dg       }
| j                  |
|||      S 7 7 7 7 1w)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>`
        NFr   r\  r  rL   r  r<   rB  	startTimer  endTimerU  )
r>  r  rh  r  rB  ri  spotPrivateGetV2AccountLedgerrg  rH  parse_ledger)r-  r  rT  r  rJ  r\  r  rh  rB  rM  rU  s              r/  fetch_ledgerzhtx.fetch_ledgerV  sG     !!!88PZ[&::=$PUW\^dfijjj77dFSS		
 }}T*H"*4.GJ#(GK $GG229gvN;;DKKQW<XYYB x4  x>>w 	" kS( ZsF   DD7DDD*D+A-DD
,DDD
Dc                    K   | j                          d{    | j                  |       d{   }| j                  |dg       }| j                  ||d      S 7 C7 ,w)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
        NrU  r  )r>  0contractPublicGetLinearSwapApiV1SwapAdjustfactorr  parse_leverage_tiers)r-  re  rJ  rM  rU  s        r/  fetch_leverage_tierszhtx.fetch_leverage_tiers  s`      !!!NNvVV< ~~h3((wHHA 	"Vs   AAAA+AAc                    | j                  |d      }| j                  |d      }g }| j                  |dg       }t        dt        |            D ]  }||   }| j                  |d      }	| j                  |dg       }
t        dt        |
            D ]  }|
|   }| j                  |d      }|j	                  | j                  |d      | j                  ||d d	      | j                  |      | j                  |d
      | j                  |d      | j                  t        j                  ||	            | j                  |	      |d         |S )Ntrade_partitionr  r  r   r  laddersr  ladderrN   min_sizemax_size)tierr]  rB  minNotionalmaxNotionalmaintenanceMarginRatemaxLeverager=  )rA  r  rl  rm  r  r  r`  r  ra  r,  r7   r  )r-  r=  r[  r  rb  tiersbracketsrq  rL  r  rd  kbracketadjustFactors                 r/  parse_market_leverage_tierszhtx.parse_market_leverage_tiers  sR   %%d,=>
##D/:>>$3q#h-( 	AA;D''l;HnnT9b9G1c'l+ !!*#//I --gx@"..xvN $ 7 7
 C#'#3#3GZ#H#'#3#3GZ#H-1->->w?Q?QR^`h?i-j#'#4#4X#>#	 			" r0  r   c                   K   |dk7  r'|dk7  r"|dk7  r|dk7  rt        | j                  dz         | j                          d{    ddd	d
d}| j                  |      }| j	                  |ddd      }||   |d}	|||	d<   d}
|d   rJ| j                  |d   d      |	d<   |d   |	d<   | j                  | j                  |	|             d{   }
nu|d   r?d|	d<   |d   |	d<   |d   |	d<   | j                  | j                  |	|             d{   }
n1|d   |	d<   | j                  | j                  |	|             d{   }
| j                  |
d      }| j                  |d      }| j                  ||||      S 7 >7 7 s7 Cw)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 timeframeNr   r   12hourr   )r   r   rt  r   amount_type
amountTyper  )r  rv  r]  rO   r=  r  r  r]  r   rN   r<   r  rU  r  )r*   r<   r>  r[  rX  rA  -contractPublicGetApiV1ContractHisOpenInterestrg  3contractPublicGetLinearSwapApiV1SwapHisOpenInterest-contractPublicGetSwapApiV1SwapHisOpenInterestrH  r  parse_open_interests_history)r-  r]  r  rT  r  rJ  r   r[  rw  rh  rM  rU  r  s                r/  fetch_open_interest_historyzhtx.fetch_open_interest_history  s    " d!2yE7Ii[_N_TWW'sstt!!!	

 V$((aP
 +%
 #GFO('+'7'7v'XGO$ &x 0GH!OOPTP[P[\cekPlmmHH'-GO$'-d|GO$'-d|GO$!UUVZVaVabikqVrssH'-d|GO$!OOPTP[P[\cekPlmmHz x0~~dF+00vueLL{ 	"( n t nsJ   A F	F B
F	FAF	F1F	F=F	F	F	F	c                   K   | j                          d{    | j                  |      }d}|3t        |      }|dkD  r#| j                  |d      }| j	                  |      }i }d}| j                  d||d      \  }}d}| j                  d||      \  }}d}	|dk(  r*| j                  | j                  ||             d{   }	n]|dk(  r*| j                  | j                  ||             d{   }	n.d|d<   | j                  | j                  ||             d{   }	| j                  |	d	g       }
| j                  |
|      S 7 37 7 ]7 0w)
a\  
        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   rO   r   rN   r  rU  )r>  r  rm  rA  r[  r  r?  *contractPublicGetApiV1ContractOpenInterestrg  *contractPublicGetSwapApiV1SwapOpenInterest0contractPublicGetLinearSwapApiV1SwapOpenInterestr  parse_open_interests)r-  re  rJ  r[  r;  ri  rh  r3  rK  rM  rU  s              r/  fetch_open_interestszhtx.fetch_open_interestsT  sv     !!!%%g.LMq ((!4U+99:JFTZ\de
!??@PRXZ`a
F!!LLT[[Y`bhMijjH& 	!!LLT[[Y`bhMijjH& (.GO$!RRSWS^S^_fhnSoppH. ~~h3((w77_ 	" k( k( qsF   EE	B*EE.E0E1.EE *EEEEc                   K   | j                          d{    | j                  |      }|d   st        | j                  dz         |d   rt	        | j                  dz         d|d   i}d}|d   rJ| j                  |d	   d
      |d
<   |d   |d<   | j                  | j                  ||             d{   }n]|d   r/d|d
<   | j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  |dg       }| j                  |d   |      }| j                  |d      }||d<   | j                  |      |d<   |S 7 Z7 7 7 `w)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:
        Nr   z3 fetchOpenInterest() supports contract markets onlyrP   z> fetchOpenInterest() does not currently support option marketsr  r<   rO   r=  r  r  r]  r   rN   rU  r   r6  r  rQ  )r>  r[  r*   r<   r/   rA  r~  rg  r  r  rH  parse_open_interestr  r  )	r-  r]  rJ  r[  rh  rM  rU  openInterestr  s	            r/  fetch_open_interestzhtx.fetch_open_interest  s     !!!V$j!TWW'\\]](tww)iijjVD\
 ('+'7'7v'XGO$ &x 0GH!LLT[[Y`bhMijjHH'-GO$!RRSWS^S^_fhnSoppH "LLT[[Y`bhMijjH| x4//Q@%%h5	$-[!#'<<	#:Z q 	" k q ksG   E9E0B!E98E393E9,E5-)E9E7AE93E95E97E9c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j	                  ||      |||||| j                  |      |d|      S )Nr6  rc  valuer  )r]  r  r  openInterestAmountopenInterestValuer  rQ  r=  )r  ra  rA  safe_open_interestr`  r  )r-  r  r[  r  rw  r  rb  s          r/  r  zhtx.parse_open_interest   s    j %%h5	!!(H5  73##Ho>&&&&x8  "(!&"Y/	(
 	 		r0  c                 ^  K   | j                          d{    | j                  |      }| j                  |      }|d   | j                  ||      |d   d}| j	                  | j                  ||             d{   }| j                  ||      }	| j                  |	||d      S 7 7 -w)aY  
        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>`
        Nr<   )rB  rw  r]  rw  r]  )r>  rB  r[  rV  privatePostMarginOrdersrg  parse_margin_loan)
r-  r]  r  rw  rJ  rB  r[  rh  rM  r7  s
             r/  borrow_isolated_marginzhtx.borrow_isolated_margin[   s      !!!==&V$ 00v>Tl

 55dkk'66RSS ,,Xx@{{;)
  	# 	" Ts"   B-B)A&B-=B+>,B-+B-c                 2  K   | j                          d{    | j                  |      }|d   | j                  ||      d}| j                  | j	                  ||             d{   }| j                  ||      }| j	                  |d|i      S 7 |7 ,w)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>`
        Nr<   rd  rw  )r>  rB  rV  privatePostCrossMarginOrdersrg  r  )r-  r  rw  rJ  rB  rh  rM  r7  s           r/  borrow_cross_marginzhtx.borrow_cross_margin~   s      !!!==& 00v>
 ::4;;wPV;WXX ,,Xx@{{;f)
  	! 	" Ys"   BBAB(B)+BBc                   K   | j                          d{    | j                  |      }| j                  dd||       d{   }|d   | j                  ||      |d}| j	                  | j                  ||             d{   }| j                  |dg       }	| j                  |	d      }
| j                  |
|      }| j                  |||d      S 7 7 7 Tw)	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>`
        NrL   re  r<   rB  rw  r  Datar   r  r>  rB  r  rV  v2PrivatePostAccountRepaymentrg  rH  r  )r-  r]  r  rw  rJ  rB  r  rh  rM  rU  loanr7  s               r/  repay_isolated_marginzhtx.repay_isolated_margin   s      !!!==&77
FTZ[[	 00v>"

 ;;DKKQW<XYY x4tQ',,T8<{{;)
  	/ 	"[ Zs5   CC,CCACCACCCc                   K   | j                          d{    | j                  |      }| j                  ddd|       d{   }|d   | j                  ||      |d}| j	                  | j                  ||             d{   }| j                  |dg       }| j                  |d      }	| j                  |	|      }
| j                  |
d|i      S 7 7 7 Sw)	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>`
        NrL   rd  r<   r  r  r   rw  r  )r-  r  rw  rJ  rB  r  rh  rM  rU  r  r7  s              r/  repay_cross_marginzhtx.repay_cross_margin   s      !!!==&77vVV	 00v>"

 ;;DKKQW<XYY x4tQ',,T8<{{;f)
  	/ 	"V Zs5   CC,CCACCACCCc                     | j                  |d      }| j                  |dd      | j                  d |      d d || j                  |      |dS )N	repayTimerepayIdrU  )r<   rB  rw  r]  r  rQ  r=  )r  r  r  r  )r-  r=  rB  r  s       r/  r  zhtx.parse_margin_loan   sZ    , %%dK8	$$T9f=//h?"Y/
 	
r0  c                   K   |t        | j                  dz         | j                  |d      }| j                  |dg      }| j	                  |      }i }|d   r	|d   |d<   n|d   |d<   |||d	<   |||d
<   |||d<   d}|d   rY|d   r*| j                  | j                  ||             d{   }nS| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  |d      }	| j                  |	d      }
| j                  |
|      }| j                  |d      S 7 7 x7 Pw)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  rO   r  r]  r<   r  start_atrc  end_atrN   r   rU  settlement_recordr  )r)   r<   r  r  r[  5contractPublicGetLinearSwapApiV1SwapSettlementRecordsrg  /contractPublicGetSwapApiV1SwapSettlementRecords/contractPublicGetApiV1ContractSettlementRecordsrH  parse_settlementsrv  )r-  r]  rT  r  rJ  r  r[  rh  rM  rU  settlementRecordsettlementss               r/  fetch_settlement_historyzhtx.fetch_settlement_history!  s    " >#DGG.d$dee!!&'26G9-V$( &x 0GH'-d|GO$"'GJ#(GK  %GH&>h!%![![\`\g\ghoqw\x!yy!%!U!UVZVaVabikqVr!ss!QQRVR]R]^egmRnooHj x0??41DE,,-=vF||K55y zsos7   B.E0E1)EE)EEAEEEcodesc                    K   | j                          d{    | j                  |       d{   }| j                  |d      }| j                  ||d      S 7 B7 +w)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>`
        NrU  rB  )r>  r  r  parse_deposit_withdraw_fees)r-  r  rJ  rM  rU  s        r/  fetch_deposit_withdraw_feeszhtx.fetch_deposit_withdraw_feeso!  s_      !!!@@HHJ ~~h///eZHHO 	"Hs   AAAA*AAc                    | j                  |dg       }| j                  |      }t        dt        |            D ]  }||   }| j	                  |d      }| j	                  |d      }| j                  |      }	d }
d }|dk(  r| j                  |d      }
|
dd}n| j                  |d	      }
|
d
d}|d d dd|d   |	<   | j                  ||      } |S )Nr  r   r  withdrawFeeTypefixedr  F)rZ  r   transactFeeRateWithdrawT)r   r  r   )rH  deposit_withdraw_feerl  rm  rA  r  ra  $assign_default_deposit_withdraw_fees)r-  rZ  rB  r  rp  rx  r  r  r  r  withdrawFeewithdrawResults               r/  parse_deposit_withdraw_feezhtx.parse_deposit_withdraw_fee!  s   @ h3**3/q#f+& 	QAJ((W=I"..z;LMO11)<KK!N')"..z;PQ&"'"
 #..z;TU&"&"
 +"&/F:{+ >>vxPF5	Q6 r0  c                    g }t        dt        |            D ]  }||   }| j                  |d      }|y| j                  |d      }|| j	                  |      d}t        dt        |            D ]:  }	||	   }
| j                  |
|      }|j                  | j                  ||             < |j                  | j                  ||   |              |S )Nr   r  settlement_timer5  )rl  rm  rH  r  r  parse_settlementr  rg  )r-  r  r[  rp  rq  
settlementr  r  timestampDetailsrx  rL  parsedSettlements               r/  r  zhtx.parse_settlements!  s    J q#k*+ 	MA$QJ??:v6D --j:KL	!* $Y 7*  q#d), SA7D'+'<'<T6'J$MM$++.>@P"QRS
 d33KNFKL	M r0  c                     | j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      || j	                  |      dS )Nr  r  settlement_price)r=  r]  r  r  rQ  )r  rA  r`  ra  r  )r-  r  r[  r  rb  s        r/  r  zhtx.parse_settlement"  sf    0 %%j2CD	##J@&&x8%%j2DE"Y/
 	
r0  c                   K   | j                          d{    | j                  |      }| j                  |dd      }d|i}|||d<   | j                  d||      \  }}d}|d   ra|d   |d<   |d	   r*| j	                  | j                  ||             d{   }n| j                  | j                  ||             d{   }nX|d
   r2|d   |d<   | j                  | j                  ||             d{   }n!t        | j                  dz   |d   z   dz         | j                  |dg       }	| j                  |	|||      S 7 17 7 7 Tw)a8  
        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>`
        Nr`  r   ra  rb  rN   r<   r   r   rO   r]  z& fetchLiquidations() does not support rT  r3  rU  )r>  r[  r  ri  5contractPublicGetLinearSwapApiV3SwapLiquidationOrdersrg  /contractPublicGetSwapApiV3SwapLiquidationOrders/contractPublicGetApiV3ContractLiquidationOrdersr/   r<   r  parse_liquidations)
r-  r]  rT  r  rJ  r[  	tradeTyperh  rM  rU  s
             r/  fetch_liquidationszhtx.fetch_liquidations:"  s}      !!!V$%%flA>	)
 $)GL!22:wO&>"(,GJh!%![![\`\g\ghoqw\x!yy!%!U!UVZVaVabikqVr!ssH &tGH!QQRVR]R]^egmRnooHtww)QQTZ[aTbbennoo0 ~~h3&&tVUEBB[ 	" zs psG   EEBEE
)EE6E9E:AE
EEEc                 ^   | j                  |d      }| j                  |d      }| j                  || j                  ||      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      || j                  |      d	      S )	Nr  r5  rc  r  r  rw  r<  )	r=  r]  r  r  r  	baseValue
quoteValuer  rQ  )rA  r  safe_liquidationr`  ra  r  )r-  rJ  r[  rb  r  s        r/  parse_liquidationzhtx.parse_liquidationy"  s    " ##KA%%k<@	$$&&x8))+x@ ,,V^D%%k7;))+x@**;8HI"Y/
&
 
 
	r0  c                   K   | j                          d{    | j                  |      }| j                  |d      }|d   st        | j                  dz         | j                  d|d       |d   |d}|||d	<   |d
   rB| j                  |dd      }|t        | j                  dz         | j                  ||      |d<   | j                  |g d      }d}|d
   rY|d   r*| j                  | j                  ||             d{   }n| j                  | j                  ||             d{   }npd}	| j                  d|d      \  }	}|	dk(  r*| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j!                  ||      S 7 7 7 7 G7 w)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>`
        Nr  r   z6 closePosition() symbol supports contract markets onlyrY   r"  r<   )r  r!  r  r   rc  rw  zP closePosition() requires an extra argument params["amount"] for inverse markets)r  rc  rw  rN   rd  )r>  r[  rA  r*   r<   check_required_argumentr  r)   r  r  6contractPrivatePostSwapApiV1SwapLightningClosePositionrg  .contractPrivatePostApiV1LightningClosePositionrk  AcontractPrivatePostLinearSwapApiV1SwapCrossLightningClosePosition<contractPrivatePostLinearSwapApiV1SwapLightningClosePositionr  )
r-  r]  r"  rJ  r[  r  rh  rw  rM  r  s
             r/  close_positionzhtx.close_position"  s    ( !!!V$((Aj!TWW'__``$$_dFC#D\
 $)6G%&)''(CF~'  3E  )E  F  F $ 8 8 HGH6#HI)f~!%!\!\]a]h]hiprx]y!zz!%!T!TUYU`U`ahjpUq!rrJ!%!C!COU[]d!eJW$!%!g!ghlhshst{  ~D  iE  "F  F!%!b!bcgcncnovx~c  "A  A&11? 	"* {r
 F AsY   GF:C1GF=	)G2F?3AG9G:)G#G$G=G?GGGr  c                   K   | j                          d{    |rdnd}d}|| j                  |      }d}| j                  d|d      \  }}d|i}d}||d   rt        | j                  dz         |d	k(  rM|t        | j                  d
z         |d   |d<   | j                  | j                  ||             d{   }|S d|d<   | j                  | j                  ||             d{   }|S 7 7 87 
w)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
        N	dual_sidesingle_sider   rd  position_moder   z4 setPositionMode can only be used for linear marketsre  zD setPositionMode requires a symbol argument for isolated margin moder<   r  r  )	r>  r[  rk  r*   r<   r)   8contractPrivatePostLinearSwapApiV1SwapSwitchPositionModerg  =contractPrivatePostLinearSwapApiV1SwapCrossSwitchPositionMode)	r-  r  r]  rJ  posModer[  r  rh  rM  s	            r/  set_position_modezhtx.set_position_mode"  s8     !!!!'+][[(F
!??@QSY[bc
FW
 VI%6TWW']]^^#~'2x(xyy(.tG$%!ZZ[_[f[fgnpv[wxxH8  )/G$%!__`d`k`klsu{`|}}H [ 	"" y ~s4   C;C5B'C;>C7?/C;.C9/C;7C;9C;)N)NN)__name__
__module____qualname__r   r*  rR  r   rY  dictr   r!   rc  r  rj  r   rr  rn  r   ru  r  r$   r  r  r  r   r  r	  r   r  r  r%  r   r1  r    rS  rW  rV  rp  ry  r  r}  r  r   r  r  r  r	   r  r  r  r   r  r  r  r  r  r  r/  r1  r   r4  r6  rI  rZ  r  rU  rw  r   r   r   r{  r  r  rv  r   r  r  r  r  r  r  r
   r  r   r  r#  r*  r"   r3  r6  rG  rE  r   r#   rb  r   r   ry  r   r  r  r   r  r  r  r   r  r   r  r  r+  r  intr  r  r  r  r3  r   r<  rD  rK  r   rW  r]  r   ra  r   rr  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  boolr  __classcell__)r.  s   @r/  r9   r9   !   s   I# IV* )+ [
z ') ;S ;<
T 
6 
EX 
( ;= !5c !5AT !5F =A '  @B P3 P@ :>b 
3 
4x *,  V  D XZ ZS Z3 Zx  3   D]4 ] ]6 ]~ 68 N NF N` 6:" hH7 hH hHT :>b c5w c5J
f 
  @DB TrS Tr TrS\ TrlA Av A AF ?CQUdhqs T3 T T3 T^a T, DHVZimvx G GS GPS Gcf G* 37TX\eg Y?C Y?s Y?RU Y?v <@d[] HY HYS HY HYbfglbm HYT
 
4 
, 8<$]ajl H HC HWZ Hquvzq{ HB +- )g ).
& KO^bkm #63 #6C #6X[ #6J -/ q: qfAC Ac AQc Q Q *, p pd	 8<B H'C H' H'T
 GKY]lpy{ A= A=SV A=fi A=F 59tZ^gi _c _ _TW _ <@daenp xS x x[^ x 9=4^bkm [?# [?S [?X[ [?z @DRVeirt d dC d_b d 04$UYbd !N !NC !Ns !Nimnsit !NF 7;\`ik  Y  Y3  YVY  Yptuzp{  YD 59tZ^gi [?c [? [?TW [?nrsxny [?z: :*j jv j jX XZ Tc T T$ ~B  TX  os  |~ R# RY RV_ Rin Rwz R  CH R* z~  GI f,c f, f,R[ f,ej f,sv f,P x|  EG U,C U,y U,PY U,ch U,qt U,n mqy{ `0 `0I `0Y `0X] `0fi `0D FH r1$|*< r1h 9=R yS y# yv 6:" R.s R.h4l 59 s2c s2j BD S 6
h 
4 JL 0S 0PTUcPd 0B =? 5 5> 5" >Bt\^ 3 @ 04$UYbd 6Q 6QC 6Qs 6Qimnyiz 6Qp 37TX\eg 4QC 4Qs 4QRU 4Qlpq|l} 4QlZ
T Z
X Z
Q\ Z
x:s :. JNVX 6:3 6: 6: 6:]h 6:p
t 
x 
= 
. ac R73 R7 R7C R7TW R7gt R7h 8: )6>Q )6V)
t )
V )
Oa )
V >BPTcgpr HYs HY# HY]` HYT+
6 +
[ +
Z? <> '7s '7+ '7R <@ 27 27| 27h 7;$]apt} ;Q ;QC ;QWZ ;Qjm ;Q  EI  JX  EY ;Qz9
$ 9
 9
. 9
vD &eBSW lP\c 3 S # X\ dg B 9=4^bkm R># R>S R>X[ R>h ?C2 G3 G GR
6 
8Xt XV Xt 8<B FPW FP4PX> FPP 8: x3 xt3&%t %x %; %N .2SW`b I?s I?# I?S I?gklwgx I?V =A 'I' 'IP] 'IR $|J\ 0 HLZ^mqz| pM pMTW pMgj pMd =A [8' [8z =? d dLBF BH Z\ !3 !c !5 !F JL c 5 @ RT &# &S &P BD $S $L
 
B <@daenp `6S `6 `6[^ `6D BFb 1Iw 1If= =~5n 
D BFTXac =Cs =C3 =Cc =C~V > CGr 323 32i 32V[ 32j CGr :d :C :r0  r9   )? ccxt.async_support.base.exchanger   ccxt.abstract.htxr   r  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#   typingr$   ccxt.base.errorsr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   ccxt.base.decimal_to_precisionr5   r6   ccxt.base.preciser7   r9    r0  r/  <module>r     s    6 )   @  @  @  @  @  @  @  @  @  * 0 - . . ' & . ) * ) , . 1 * + 3 4 %fK(K fKr0  