
    !:h                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( d dl'm)Z) d dl'm*Z* d d	l'm+Z+ d d
l'm,Z, d dl'm-Z- d dl'm.Z. d dl'm/Z/ d dl'm0Z0 d dl'm1Z1 d dl'm2Z2 d dl'm3Z3 d dl'm4Z4 d dl'm5Z5 d dl'm6Z6 d dl'm7Z7 d dl8m9Z9 d dl8m: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    B/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/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                 \   | j                          d}| j                  dd|      \  }}| j                  ddd      }d}|dk7  r|r| j                  |d| j                  d         }|dk(  r,|d	k(  r| j                         }nr|d
k(  rm| j                         }n\|dk(  r,|d	k(  r| j                         }nA|d
k(  r<| j                         }n+|dk(  r&| j                         }n|dk(  r| j                         }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 )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_statusm  s    	
!??tU[\
F"00@TV[\$7&&vy$,,GW:XYGV#h&#MMOH	)#NNPHx'h&#OOQH	)#PPRHz)::<6!??AHD #((8<I "+t"3-&&x6G8R@J(([AI'61TFx<H'',?HnnX.G""8U3C
 	
r0  c                 F   | j                  | j                  di       }| j                  | j                  dd      }| j                  |d|      }| j                  |d|      }d}|dk(  s|dk(  r| j                  |      }n| j	                  |      }| j                  |dd	      S )
a  
        fetches the current integer timestamp in milliseconds from the exchange server

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        r   r  rL   typeNrO   rN   datar6  )rH  r  rA  contractPublicGetApiV1TimestampspotPublicGetV1CommonTimestampsafe_integer_2)r-  rJ  r  r  rT  rM  s         r/  
fetch_timezhtx.fetch_timeJ  s     //$,,R@&&t||]FK=5H$&.;;FCH::6BH ""8VT::r0  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_feeh  s[     ##C2&&x8%%c+<=%%c+<=
 	
r0  r]  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j	                  |di       }| j                  ||      S )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>`
        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|
 @@WV\A]^  x4a,%%eV44r0  re  c                     | j                          || j                  }i }t        dt        |            D ]+  }||   }| j	                  | j                  |      |      ||<   - |S )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  so     	?llGq#g,' 	]AQZF!<<T^^F=SU[\F6N	] r0  r<   c                     d|i}| j                  | j                  ||            }| j                  | j                  |di             S )a&  
 @ignore

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

        :param str id: market id
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: the limits object of a market structure
        r]  rU  )spotPublicGetV1CommonExchangerg  parse_trading_limitsrH  )r-  r<   rJ  rh  rM  s        r/  rn  zhtx.fetch_trading_limits_by_id  sM     b
 55dkk'66RS" ((62)NOOr0  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                    | j                   d   r| j                          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        dt        |            D ]  }| j                  |||         } |S )a   
        retrieves data on all markets for huobi

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r  Nr   r  r   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array_concat)r-  rJ  r  
allMarketspromisesr  rq  keys           r/  fetch_marketszhtx.fetch_markets  sS    <<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 q#h-( 	DA**:x{CJ	Dr0  rT  r3  c                    |dk(  }i }d}|s|dk(  r'd|d<   | j                  | j                  ||            }nt|dk(  ro|dk(  r"| j                  | j                  ||            }nH|dk(  rC| j                  | j                  ||            }n!| j	                  | j                  ||            }| 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 )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(PPQUQ\Q\]dflQmnI%8##NNt{{[bdjOklHV^#NNt{{[bdjOklH88Wf9UVHn ..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 r0  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_tickerI  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                 f   | j                          | j                  |      }i }d}|d   r*|d   |d<   | j                  | j                  ||            }n|d   r^|d   r*|d   |d<   | j	                  | j                  ||            }nX|d   rS|d   |d<   | j                  | j                  ||            }n)|d   |d<   | j                  | j                  ||            }| j                  |d	i       }| j                  ||      }| j                  |d
      }||d<   | j                  |      |d<   |S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

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

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r<   r  r   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  sM    	V$('-d|GO$KKDKKX_agLhiHIh$*4L!CCDKKPWY_D`a+1$<(II$++V]_eJfg &tGH;;DKKQW<XYHX x4""40%%h5	'{!\\)4zr0  c                 d   | j                          | 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|r7|
rd|d<   n|rd|d<   nd|d<   | j                  | j                  ||            }n|r`|
r"| j                  | j                  ||            }nu|r"| j                  | j                  ||            }nQt        | j                  dz         t        | j                  dz         | j                  | j                  ||            }| j                  |ddg       }| j                  |||      }| j                  |d|      S )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>`
        r   Nr3  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  s    	%%g.  !,[['F'61Q&7P99.&RXYf99.&RXY&.("X%i'+/8GO,/5GO,/4GO,TTUYU`U`ahjpUqr#LLT[[Y`bhMijH#RRSWS^S^_fhnSopH&tww  2U  (U  V  V"477  .O  $O  P  P66t{{7F7STHf %%hD
$$Z&A++GXwGGr0  c                 (   | j                          | j                  |      }| j                  |      }d}d}| j                  d||      \  }}| j	                  d||      \  }}d}|dk(  s|dk(  r|dk(  r| j                  |      }nV|dk(  r|dk(  r| j                  |      }n:|dk(  r|dk(  r| j                  |      }nt        | j                  dz   |z   dz         | j                  |d	i       }| j                  |d
g       }| j                  ||      S )ax  
        fetches the last price for multiple markets

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

        :param str[] [symbols]: unified symbols of the markets to fetch the last prices
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of lastprices structures
        Nr   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_pricesb	  s3    	%%g.--g699:KVU[\99:KVU[\fV^!1H9LDDVLH4 fn7i#7>>vFH. hW	%988@H0 tww)OORVVYgghhx4~~dFB/%%dG44r0  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                    | j                          | j                  |      }ddi}d}|d   r*|d   |d<   | j                  | j                  ||            }n|d   r^|d   r*|d   |d	<   | j	                  | j                  ||            }n|d
   r|d   |d<   | j                  | j                  ||            }na|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|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         )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
        rT  step0Nr   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	  s    	V$ G

 ('-d|GO$DDT[[QXZ`EabHIh$*4L!<<T[[RX=YZ+1$<(BB4;;wX^C_` QJUb[u{RU$TWW  0B  &B  C  C C<',GG$ &tGH44T[[&5QRH6 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qr0  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-  r0  r[  rb  r]  r  rB  r   rT  	typePartsrC  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                     d}|| j                  |      }d}| j                  d||      \  }}|dk7  rt        | j                  dz         | j	                  |||||      S )a-  
        fetch all the trades made from a single order

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

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr   rL   z6 fetchOrderTrades() is only supported for spot markets)r[  r?  r/   r<   fetch_spot_order_trades)r-  r<   r]  rR  r  rJ  r[  rK  s           r/  fetch_order_tradeszhtx.fetch_order_trades
  st     [[(F
!??@RTZ\bc
Ftww)aabb++BufMMr0  c                     | j                          d|i}| j                  | j                  ||            }| j                  |d   d||      S )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>`
        r4  rU  N)r>  .spotPrivateGetV1OrderOrdersOrderIdMatchresultsrg  parse_trades)r-  r<   r]  rR  r  rJ  rh  rM  s           r/  rT  zhtx.fetch_spot_order_trades
  sW     	
 FFt{{SZ\bGcd  &!14FFr0  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S d}|| j                  |      }d}| j	                  d||      \  }}i }d}	|dk(  rb|| j                  |      }|d   |d<   |||d<   |||d	<   | j                  d
||      \  }}| j                  | j                  ||            }	n4|t        | j                  dz         |d   |d<   d|d<   |||d<   | j                  d||      \  }}|||d<   |d   rkd}
| j                  d|      \  }
}|
dn|
}
|
dk(  r"| j                  | j                  ||            }	n|
dk(  r| j                  | j                  ||            }	ny|d   rt|dk(  r*|d   |d<   | j                  | j                  ||            }	nE|dk(  r"| j                  | j                  ||            }	nt        | j                  dz   |z   dz         | j!                  |	d      }t#        |t$              s| j!                  |d      }| j'                  ||||      S )a%  

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

        fetch all trades made by the user
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Fr   paginateNrL   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  rX  )r-  r]  rR  r  rJ  rZ  r[  rK  rh  rM  r  re  s               r/  fetch_my_tradeszhtx.fetch_my_trades
  s     	88R\]&44_feUZ\bcc[[(F
!??QWY_`
F
& !V,$*4L! "' (-%"66z7FSOGV==dkk'SY>Z[H~'2_(_``"(,GJ$%GL! (-%"66z7FSOGV ',$h!
%)%G%GY_%`"
F)3);W*
+#[[\`\g\ghoqw\xyH7*#``aealalmtv|a}~H	")(.z(:GH%#UUVZVaVabikqVrsH6)#UUVZVaVabikqVrsH&tww1U'UXb'beo'oppF 62&$'__VX6F  >>r0  r  c                    | j                          | j                  |      }i }|t        |d      |d<   d}|d   r^|d   r*|d   |d<   | j                  | j	                  ||            }n|d   r|d   |d	<   | j                  | j	                  ||            }n|d
   rV|d   |d	<   |d   r"| j                  | j	                  ||            }nP|d   rK| j                  | j	                  ||            }n)|d   |d<   | j                  | j	                  ||            }| j                  |dg       }g }	t        dt        |            D ]X  }
| j                  ||
   dg       }t        dt        |            D ](  }| j                  ||   |      }|	j                  |       * Z | j                  |	d      }	| j                  |	|d   ||      S )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  rQ  r  sort_byfilter_by_symbol_since_limit)r-  r]  rR  r  rJ  r[  rh  rM  rU  rp  rq  re  jr0  s                 r/  fetch_tradeszhtx.fetch_tradesv  s    	V$
 !%.GFO(i $*4L!CCDKKPWY_D`a!+1$<(OOPTP[P[\cekPlmF^'-d|GO$i II$++V]_eJfg!OOPTP[P[\cekPlm &tGH;;DKKQW<XYH2 x4q#d)$ 	%A__T!Wfb9F1c&k* %((F;e$%	%
 fk2009I5RWXXr0  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           	      	   | j                          d}| j                  |dd      \  }}|r| j                  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   rY|d   r|d   |d<   |	dk(  r#| j                  | j                  ||            }n!|	dk(  r#| j!                  | j                  ||            }n|	dk(  r't#        | j$                  dz   |d   z   dz   |	z   dz         | j'                  | j                  ||            }n|d   r|d   |d<   |	dk(  r#| j)                  | j                  ||            }nt|	dk(  r't#        | j$                  dz   |d   z   dz   |	z   dz         |	dk(  r#| j+                  | j                  ||            }n | j-                  | j                  ||            }n|d   rO|d   |d<   |d   r|	dk(  r#| j/                  | j                  ||            }n|	dk(  r't#        | j$                  dz   |d   z   dz   |	z   dz         |	dk(  r#| j1                  | j                  ||            }nn| j3                  | j                  ||            }nK|d   rE|	dk(  r#| j)                  | j                  ||            }n|	dk(  r't#        | j$                  dz   |d   z   dz   |	z   dz         |	dk(  r"| j+                  | j                  ||            }n| j-                  | j                  ||            }n|d   |d<   d}| j                  |ddd      \  }}|s3|t        |d      |d<   | j5                  | j                  ||            }nR|| j                  |dz        |d<   |||d<   |t        d|      |d<   | j7                  | j                  ||            }| j9                  |d g       }| j;                  |||||      S )!a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

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

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param str [params.useHistoricalEndpointForSpot]: True/false - whether use the historical candles endpoint for spot markets or default klines endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fr   rZ  r  period	priceTyper  N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   rF  omithandle_param_integerparse_to_intry  parse_timeframesecondssum1contractPublicGetIndexMarketHistoryMarkPriceKlinerg  (contractPublicGetIndexMarketHistoryIndexr*   r<   #contractPublicGetMarketHistoryKline;contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline>contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline/contractPublicGetLinearSwapExMarketHistoryKline5contractPublicGetIndexMarketHistorySwapMarkPriceKline8contractPublicGetIndexMarketHistorySwapPremiumIndexKline)contractPublicGetSwapExMarketHistoryKlinespotPublicGetMarketHistoryKline!spotPublicGetMarketHistoryCandlesr  parse_ohlcvs)r-  r]  	timeframerR  r  rJ  rZ  r[  rh  r~  r  untilSecondsdurationcalcualtedEndnowstartrM  useHistoricalrU  s                      r/  fetch_ohlcvzhtx.fetch_ohlcv  s~   $ 	88zZ&::<QVX]_hjprvww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!&#UUVZVaVabikqVrsH')#LLT[[Y`bhMijH.0$TWWs]VF^%CFa%adm%mp}%}~~#GGT[]cHdeH!+1$<(&#__`d`k`klsu{`|}H')$TWWs]VF^%CFa%adm%mp}%}~~.0#bbcgcncnovx~c   AH#SSTXT_T_`gioTpqHF^'-d|GO$i &#YYZ^ZeZefmouZvwH')$TWWs]VF^%CFa%adm%mp}%}~~.0#\\]a]h]hiprx]yzH#MMdkkZaciNjkH!&#__`d`k`klsu{`|}H')$TWWs]VF^%CFa%adm%mp}%}~~.0#bbcgcncnovx~c   AH#SSTXT_T_`gioTpqH &tGH M$($A$A&,Xvx|$}!M6 $&)%&6GFO??GU[@\] $&*&7&7&EGFO+$0GDM$&)$&6GFOAA$++gW]B^_ ~~h3  vy%GGr0  c                     | j                          | j                  |      }| j                  |d      }| j                  |      S )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
        rU  )r>  spotPrivateGetV1AccountAccountsrH  parse_accountsr-  rJ  rM  rU  s       r/  fetch_accountszhtx.fetch_accountsW  sC     	77? x0""4((r0  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_accountn  sa     !!'62t||^RH|VV<""7D1	
 	
r0  r  c                    | j                         }| 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 )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
        	accountId
account-idNrL   rb  r  rc  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  s*    %%'%%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5r0  c                 h   | j                  |      }| 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 )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
        rU  networkChainIdsByNamesnetworkNamesByChainIdsr   r@  	assetTypecryptochainschain	baseChaindisplayNameminDepositAmtNrx  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   rv  
chainEntryuniqueChainIdtitlenetworkCodes                     r/  fetch_currencieszhtx.fetch_currencies  s    ::6B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>	~ r0  	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                    | j                          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|rG|r#| j                  | j                  ||            }n | j                  | j                  ||            }n| j                          | j                  |dd|      }||d<   | j                  | j                  ||            }n|r"| j                  | j                  ||            }n|rF|r"| j                  | j                  ||            }ni| j!                  | j                  ||            }nG|
rE|r"| j#                  | j                  ||            }n!| j%                  | j                  ||            }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 )%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   rc  rb  rM   r  r=  rU  r   r]  r  r@  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  ri  %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  rc  rb  rM   rM  r  rp  rU  rq  r"  r]  balances	subResultrv  balancer  r  marginAssetr  r  rb  
subBalancer  ri  r[  r@  accountsByCodes'                                          r/  fetch_balancezhtx.fetch_balance0  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#II$++V]_eJfgH#NNt{{[bdjOklH""$ 99$dFS	(1%OOPTP[P[\cekPlmOOPTP[P[\cekPlmHQQRVR]R]^egmRnoVVW[WbWbcjlrWstKKDKKX_agLhiKKDKKX_agLhi@ )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r0  c                 T   | j                          d}|| j                  |      }d}| j                  d||      \  }}i }d}|dk(  r_| j                  |d      }|#| j	                  | j                  ||            }ng||d<   | j                  | j                  ||            }n?|t        | j                  dz         | j                  |dd      }|||d<   n||d<   | j                  |ddg      }|d	   |d
<   |d   rkd}	| j                  d|      \  }	}|	dn|	}	|	dk(  r"| j                  | j                  ||            }n|	dk(  r| j                  | j                  ||            }ny|d   rt|dk(  r*|d   |d<   | j                  | j                  ||            }nE|dk(  r"| j                  | j                  ||            }nt!        | j                  dz   |z   dz         | j#                  |d      }
t%        |
t&              r| j#                  |
d      }
| j)                  |
      S )a  
        fetches information on an order made by the user

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

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   rL   clientOrderIdr4  z( fetchOrder() requires a symbol argumentclient_order_idr5  r<   r  r   rb  rc  r   rO   r  r]  rN   z fetchOrder() does not support rd  rU  r   )r>  r[  r?  rA  )spotPrivateGetV1OrderOrdersGetClientOrderrg  "spotPrivateGetV1OrderOrdersOrderIdr)   r<   r  r  ri  /contractPrivatePostLinearSwapApiV1SwapOrderInfo4contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo)contractPrivatePostApiV1ContractOrderInfo)contractPrivatePostSwapApiV1SwapOrderInfor/   rH  r  r  parse_order)r-  r<   r]  rJ  r[  rK  rh  rM  r  r  rB  s              r/  fetch_orderzhtx.fetch_orderb  sj     	[[(F
!??fV\]
F
  ,,V_EM(  II$++V]_eJfg&(
#BB4;;wX^C_`~'2\(\]] ..v7H/ZM$&(
#-:)*6,=+OP'-d|GO$h!
%)%G%GV\%]"
F)3);W*
+#SSTXT_T_`gioTpqH7*#XXY]YdYdelntYuvH	")(.z(:GH%#MMdkkZaciNjkH6)#MMdkkZaciNjkH&tww1R'RU_'_bl'lmm| &1eT"OOE1-E&&r0  c                     d }||v r||   }n| j                         }|d   dk(  r| j                  |d      |d<   |d   dk(  r| j                  |d      |d<   |S )NrT  r0  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                 0   | j                  | j                  dd      }|dk(  r|t        | j                  dz         | j	                          d }d|i}|| j                  |      }|d   |d<   |||d<   | j                  |d      |d	<   | j                  d	||      \  }}|||d
<   d }	|dk(  r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j                  |	dg       }
| j                  |
|||      S )Nr  r  z) fetchOrders() requires a symbol argumentstatesr<   r]  r\  i L
r]  r[  rU  )rA  r  r)   r<   r>  r[  r  rg  spotPrivateGetV1OrderOrdersrg  spotPrivateGetV1OrderHistoryr  parse_orders)r-  r	  r]  rR  r  rJ  methodr[  rh  rM  rU  s              r/  fetch_spot_orders_by_stateszhtx.fetch_spot_orders_by_states8  s>   !!$,,0KMop77~'2](]^^ f
" [[(F &tGH$)GL!"&((52E"FGJ22:wO#GFO7777GV8TUH88Wf9UVH6 ~~h3  vue<<r0  c                 ,    | j                  d||||      S )NzGpre-submitted,submitted,partial-filled,filled,partial-canceled,canceledr  r-  r]  rR  r  rJ  s        r/  fetch_spot_orderszhtx.fetch_spot_orders{  s6    //0y  |B  DI  KP  RX  Y  	Yr0  c                 ,    | j                  d||||      S )Nz filled,partial-canceled,canceledr  r  s        r/  fetch_closed_spot_orderszhtx.fetch_closed_spot_orders~  s     //0RTZ\achjpqqr0  c                 F   |t        | j                  dz         | j                          | 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   rLd }| j                  d|      \  }}|dn|}|dk(  r|r#| j                  | j                  ||            }n9|	r#| j                  | j                  ||            }n|
r#| j                  | j                  ||            }n| j                  | j                  ||            }n|dk(  r|r#| j                  | j                  ||            }n|	r#| j!                  | j                  ||            }n||
r#| j#                  | j                  ||            }nW| j%                  | j                  ||            }n4|d   r.|d   r|r#| j'                  | j                  ||            }n|	r"| j)                  | j                  ||            }n|
r"| j+                  | j                  ||            }n| j-                  | j                  ||            }n|d   r|d   |d<   |r"| j/                  | j                  ||            }ni|	r"| j1                  | j                  ||            }nE|
r"| j3                  | j                  ||            }n!| j5                  | j                  ||            }| j                  |d      }t7        |t8              s| j                  |dg       }| j;                  ||||      S ) Nz1 fetchContractOrders() requires a symbol argumentr   r>  )r^  r   stopr  stopLossTakeProfitr  Fr  r  r  r  ra  r<   r  r"  r  r_  r   r   rT  r`  r   fetchContractOrdersrb  rc  r   rN   rO   r  r]  rU  orders)r)   r<   r>  r[  safe_bool_2rH  r  r  rg  ri  6contractPrivatePostLinearSwapApiV1SwapTriggerHisordersrg  3contractPrivatePostLinearSwapApiV1SwapTpslHisorders4contractPrivatePostLinearSwapApiV1SwapTrackHisorders/contractPrivatePostLinearSwapApiV3SwapHisorders;contractPrivatePostLinearSwapApiV1SwapCrossTriggerHisorders8contractPrivatePostLinearSwapApiV1SwapCrossTpslHisorders9contractPrivatePostLinearSwapApiV1SwapCrossTrackHisorders4contractPrivatePostLinearSwapApiV3SwapCrossHisorders0contractPrivatePostSwapApiV1SwapTriggerHisorders-contractPrivatePostSwapApiV1SwapTpslHisorders.contractPrivatePostSwapApiV1SwapTrackHisorders)contractPrivatePostSwapApiV3SwapHisorders0contractPrivatePostApiV1ContractTriggerHisorders-contractPrivatePostApiV1ContractTpslHisorders.contractPrivatePostApiV1ContractTrackHisorders)contractPrivatePostApiV3ContractHisordersr  r  r  )r-  r]  rR  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'#ZZ[_[f[fgnpv[wxH'#WWX\XcXcdkmsXtuH#XXY]YdYdelntYuvH#SSTXT_T_`gioTpqHw&#__`d`k`klsu{`|}H'#\\]a]h]hiprx]yzH#]]^b^i^ijqsy^z{H#XXY]YdYdelntYuvHIf~#TTUYU`U`ahjpUqrH'#QQRVR]R]^egmRnoH#RRSWS^S^_fhnSopH#MMdkkZaciNjkH!$*:$6!#TTUYU`U`ahjpUqrH'#QQRVR]R]^egmRnoH#RRSWS^S^_fhnSopH#MMdkkZaciNjkH^ 62&$'__VXr:F  >>r0  c           	      R    ddi}| j                  |||| j                  ||            S )Nr   z5,6,7)r,  rg  )r-  r]  rR  r  rJ  rh  s         r/  fetch_closed_contract_ordersz htx.fetch_closed_contract_orders^  s3    g
 ))&%GU[@\]]r0  c                 ,   | j                          d}|| j                  |      }d}| j                  d||      \  }}|dk(  xs |dk(  }|r |t        | j                  dz   |z   dz         |r| j                  ||||      S | j                  ||||      S )a  

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

        fetches information on multiple orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
        :param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.trailing]: *contract only* set to True if you want to fetch trailing stop orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   rN   rO   z. fetchOrders() requires a symbol argument for  orders)r>  r[  r?  r)   r<   r,  r  )r-  r]  rR  r  rJ  r[  rK  r   s           r/  fetch_orderszhtx.fetch_ordersd  s    * 	[[(F
!??vW]^
F&(EjH.D#DGG.^$^ak$knw$wxx--feUFKK))&%GGr0  c                 6   | j                          d}| j                  |dd      \  }}|r| j                  d||||d      S d}|| j                  |      }d}| j	                  d||      \  }}|dk(  r| j                  ||||      S | j                  ||||      S )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>`
        Frp   rZ  rB   NrL   )r>  r  rf  r[  r?  r  r.  )r-  r]  rR  r  rJ  rZ  r[  rK  s           r/  fetch_closed_orderszhtx.fetch_closed_orders  s    & 	88ATV`a&445H&RWY^`fhkll[[(F
!??@SU[]cd
F00vNN44VUE6RRr0  c                    | j                          d}|| j                  |      }i }d}| j                  d||      \  }}d}|dk(  r||d   |d<   | j                  |d      }	|	o| j	                          t        dt        | j                              D ]=  }
| j                  |
   }| j                  |d      dk(  s(| j                  |d      }	|	= n |	|d<   |||d	<   | j                  |d      }| j                  | j                  ||            }n|t        | j                  d
z         |||d<   |d   |d<   | j                  |dd      }| j                  |d      }| j                  |dd      }| j                  |g d      }|d   rLd}| j!                  d|      \  }}|dn|}|dk(  r|r#| j#                  | j                  ||            }n9|r#| j%                  | j                  ||            }n|r#| j'                  | j                  ||            }n| j)                  | j                  ||            }n|dk(  r|r#| j+                  | j                  ||            }n|r#| j-                  | j                  ||            }n||r#| j/                  | j                  ||            }nW| j1                  | j                  ||            }n4|d   r.|d   r|r#| j3                  | j                  ||            }n|r"| j5                  | j                  ||            }n|r"| j7                  | j                  ||            }n| j9                  | j                  ||            }n|d   r|d   |d<   |r"| j;                  | j                  ||            }ni|r"| j=                  | j                  ||            }nE|r"| j?                  | j                  ||            }n!| jA                  | j                  ||            }| j                  |d      }tC        |tD              s| j                  |dg       }| jG                  ||||      S )a   

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

        fetch all unfilled currently open orders
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
        :param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :param boolean [params.trailing]: *contract only* set to True if you want to fetch trailing stop orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   rL   r<   r]  r  r   rT  r[  z- fetchOpenOrders() requires a symbol argumentra  r  r  r  r  r  Fr  r   rb  rc  r   rN   rO   r  rU  r  )$r>  r[  r?  rA  r  rl  rm  r  r  spotPrivateGetV1OrderOpenOrdersrg  r)   r<   r  rH  r  ri  7contractPrivatePostLinearSwapApiV1SwapTriggerOpenorders4contractPrivatePostLinearSwapApiV1SwapTpslOpenorders5contractPrivatePostLinearSwapApiV1SwapTrackOpenorders0contractPrivatePostLinearSwapApiV1SwapOpenorders<contractPrivatePostLinearSwapApiV1SwapCrossTriggerOpenorders9contractPrivatePostLinearSwapApiV1SwapCrossTpslOpenorders:contractPrivatePostLinearSwapApiV1SwapCrossTrackOpenorders5contractPrivatePostLinearSwapApiV1SwapCrossOpenorders1contractPrivatePostSwapApiV1SwapTriggerOpenorders.contractPrivatePostSwapApiV1SwapTpslOpenorders/contractPrivatePostSwapApiV1SwapTrackOpenorders*contractPrivatePostSwapApiV1SwapOpenorders1contractPrivatePostApiV1ContractTriggerOpenorders.contractPrivatePostApiV1ContractTpslOpenorders/contractPrivatePostApiV1ContractTrackOpenorders*contractPrivatePostApiV1ContractOpenordersr  r  r  )r-  r]  rR  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;;DKKQW<XYH~'2a(abb ',$'-d|GO$&&vvyAG!%9M!N~~fj%@HYYv'\]Fh!
%)%G%GHY[a%b"
F)3);W*
+#'#_#_`d`k`klsu{`|#}+#'#\#\]a]h]hiprx]y#z!#'#]#]^b^i^ijqsy^z#{#'#X#XY]YdYdelntYu#v7*#'#d#deiepepqx  {A  fB  $C+#'#a#abfbmbmnuw}b~#!#'#b#bcgcncnovx~c  $A#'#]#]^b^i^ijqsy^z#{	"&>#'#Y#YZ^ZeZefmouZv#w+#'#V#VW[WbWbcjlrWs#t!#'#W#WX\XcXcdkmsXt#u#'#R#RSWS^S^_fhnSo#pH%(.z(:GH%#'#Y#YZ^ZeZefmouZv#w+#'#V#VW[WbWbcjlrWs#t!#'#W#WX\XcXcdkmsXt#u#'#R#RSWS^S^_fhnSo#pr 62&$'__VXr:F  >>r0  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filledrH  	submittedr  r  23456711rA  r-  r   statusess      r/  parse_order_statuszhtx.parse_order_status  sL     % *"!
$ &&99r0  rB  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_strr4  r  order_price_typerT  r  r   r   r  r]  )r3  r2  r  r  client-order-idr[  field-cash-amountvolumerw  )zfilled-cash-amountr_  r:  )r8  zfield-amountr9  r  order_pricer;  z
field-feesrZ  r=  sellr  r  r?  trade_avg_pricere  reduce_onlyFTr=  r<   r  r  rQ  lastTradeTimestampr  postOnlyr   r  
stop-pricetrigger_pricer  r}  rK  )	remainingr   
reduceOnlyrZ  re  )r  rW  rF  rA  r  r!  safe_integer_nfindr  rH  r  
safe_orderr  )r-  rB  r[  rejectedCreateOrdersr   r<   r   rT  	orderTyperb  r  r  r}  rw  rK  r  rL  rZ  rN  rM  r  re  reduceOnlyIntegerrj  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                     | j                          | j                  |      }|d   st        | j                  dz         d|d<   | j	                  |dd|d|      S )a  
        create a market buy order by providing the symbol and cost

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

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rL   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r[  buyN)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  s`     	V$f~tww)ddee6;23  5$fMMr0  r   rw  r  c	                     |t        | j                  dz         |t        | j                  dz         ||d<   ||d<   | j                  ||||||      S )a  
        create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency, or number of contracts
        :param float [price]: the price for the order to be filled at, in units of the quote currency, ignored in market orders
        :param float trailingPercent: the percent to trail away from the current market price
        :param float trailingTriggerPrice: the price to activate a trailing order, default uses the price argument
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        zA createTrailingPercentOrder() requires a trailingPercent argumentzF createTrailingPercentOrder() requires a trailingTriggerPrice argumenttrailingPercenttrailingTriggerPrice)r)   r<   rs  )	r-  r]  rT  r   rw  r  rv  rw  rJ  s	            r/  create_trailing_percent_orderz!htx.create_trailing_percent_order  sk     "#DGG.q$qrr'#DGG.v$vww$3 !)=%&  tVUFKKr0  c                    | j                          | j                          | j                  |      }d}| j                  d|      \  }}| j	                  |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 )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  	stopPricerg  r  z: createOrder() requires a triggerPrice for a trigger orderrb  ltegteoperatorrg  r  r  zstop-r  r  z  createOrder() does not support r0  r[  r  r  r  r  z-fokr  r  r  r  r^  r  rb  zsuper-margin-apisourcerc  z
margin-apic2czc2c-margin-apirr  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{  rg  r  r^  r~  r  )r>  r  r[  ri  r  replacerH  r  rF  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  ro  r  r  r  defaultOperatorstopOperatorrf  r  r  r  brokerIdquoteAmountr  r}  rJ  rI  r  s                               r/  create_spot_order_requestzhtx.create_spot_order_request  s    	V$
!??vV
F11&.*fU	 $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++r0  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  r`  r  Nr[  	post_onlyr  r  r  fokr  r  r  r{  rh  r
  sl_trigger_pricer  tp_trigger_pricerv  callback_raterw  triggerTypetrigger_typelerh  ra  sl_order_price_typesl_order_pricetp_order_price_typetp_order_price100active_pricer]  formula_pricer  r  r  r  rj  rd  Fr   )	leverRate
lever_rater  r  r  r  offsetr  r  channel_code)rj  r  r{  r
  r  r  r  r  r  rv  rw  r  )r[  r  r  rA  safe_number_nsafe_number_2r  ra  r  r7   
string_divparse_to_numericrX  r  r  rk  r  rH  r  rg  )r-  r]  rT  r   rw  r  rJ  r[  rh  rf  r  r  stopLossTriggerPricetakeProfitTriggerPricerv  rw  isTrailingPercentOrder	isTriggerisStopLossTriggerOrderisTakeProfitTriggerOrderr  trailingPercentStringr  rj  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                    | j                          | j                  |      }| j                  |g d      }| j                  |dd      }	| j                  |dd      }
| j	                  |d      }|du}|du}|	du}|
du}d}|d   rC|rt        | j                  d	z         | j                  ||||||      }| j                  |      }n| j                  ||||||      }|d
   rd}| j                  d|      \  }}|dn|}|dk(  rT|r| j                  |      }nq|s|r| j                  |      }nZ|r| j                  |      }nE| j                  |      }n2|dk(  r,|r| j                  |      }n|s|r| j!                  |      }n |r| j#                  |      }n| j%                  |      }n|d   r| j'                  |d      }|t)        | j                  dz         |d   rP|r| j+                  |      }n|s|r| j-                  |      }nz|r| j/                  |      }nf| j1                  |      }nT|d   rO|r| j3                  |      }n;|s|r| j5                  |      }n%|r| j7                  |      }n| j9                  |      }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 )(a  
        create a trade order

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

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

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

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   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   rb  rc  r   rN   rO   rU  successerrors)r>  rl  rm  rA  r*   r<   rH  ri  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~#==hdTZ\acno#AA(DRVX^`egrs99\<@L!!,/9	0: &>77GH%3GM"h)3);W*
+#TTU\]H7*#YYZabH	"&>#NNwWHH%#NNwWHT &>__Xvr:F??8VR8DoodIr:G__T8R8F&&w7F  00r0  c                 d   | j                          d}|| j                  |      }d}| j                  d||      \  }}i }d}|dk(  ry| j                  |dd      }|(||d<   | j	                  | j                  ||            }n||d<   | j                  |ddg      }| j                  | j                  ||            }nM|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   rLd}| j                  d|      \  }}|dn|}|dk(  r|	r#| j                  | j                  ||            }nP|
r#| j                  | j                  ||            }n+|r#| j!                  | j                  ||            }n| j#                  | j                  ||            }n|dk(  r|	r#| j%                  | j                  ||            }n|
r#| j'                  | j                  ||            }n|r#| j)                  | j                  ||            }nn| j+                  | j                  ||            }nK|d   r'|d   r|	r#| j-                  | j                  ||            }n|
r"| j/                  | j                  ||            }n|r"| j1                  | j                  ||            }n| j3                  | j                  ||            }n|d
   r|	r"| j5                  | j                  ||            }n|
r"| j7                  | j                  ||            }nd|r"| j9                  | j                  ||            }n@| j;                  | j                  ||            }nt=        | j                  dz   |z   dz         | j                  | j?                  ||      |dd      S )a  
        cancels an open order
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: *contract only* if the order is a trigger trigger order or not
        :param boolean [params.stopLossTakeProfit]: *contract only* if the order is a stop-loss or take-profit order
        :param boolean [params.trailing]: *contract only* set to True if you want to cancel a trailing order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NrV   rL   r^  r  r4  z) cancelOrder() requires a symbol argumentr  r5  rO   r  r]  r<   r  r  r  r  r  Fr  r   rb  rc  r   rN   z  cancelOrder() does not support rd  rH  )r<   r   ) r>  r[  r?  r  /spotPrivatePostV1OrderOrdersOrderIdSubmitcancelrg  r  3spotPrivatePostV1OrderOrdersSubmitCancelClientOrderr)   r<   r  rH  r  ri  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  sw    	[[(F
!??vW]^
F
  ..v7H/ZM$&(
#OOPTP[P[\cekPlm-:)*6,=+OPSSTXT_T_`gioTpq~'2](]^^ ..v7H/ZM$&(
#-:)*6,=+OPh$*:$6!+1$<(&&vvyAG!%9M!N~~fj%@HYYv'\]Fh!
%)%G%GW]%^"
F)3);W*
+#'#[#[\`\g\ghoqw\x#y+#'#X#XY]YdYdelntYu#v!#'#Y#YZ^ZeZefmouZv#w#'#T#TUYU`U`ahjpUq#r7*#'#`#`aealalmtv|a}#~+#'#]#]^b^i^ijqsy^z#{!#'#^#^_c_j_jkrtz_{#|#'#Y#YZ^ZeZefmouZv#w	"&>#'#U#UVZVaVabikqVr#s+#'#R#RSWS^S^_fhnSo#p!#'#S#STXT_T_`gioTp#q#'#N#Nt{{[bdjOk#lH%#'#U#UVZVaVabikqVr#s+#'#R#RSWS^S^_fhnSo#p!#'#S#STXT_T_`gioTp#q#'#N#Nt{{[bdjOk#l"477-O#OR\#\_i#ijj( {{4++Hf= @
  	r0  c                    | j                          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                  ||            }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   rd}| j                  d|      \  }}|dn|}|dk(  rm|	r#| j!                  | j                  ||            }n|
r#| j#                  | j                  ||            }n| j%                  | j                  ||            }nt|dk(  rn|	r#| j'                  | j                  ||            }nI|
r#| j)                  | j                  ||            }n$| j+                  | j                  ||            }n|d   r|d   rj|	r"| j-                  | j                  ||            }n|
r"| j/                  | j                  ||            }n| j1                  | j                  ||            }n|d   r|	r"| j3                  | j                  ||            }nd|
r"| j5                  | j                  ||            }n@| j7                  | j                  ||            }nt9        | j                  dz   |z   dz         | j;                  |d       }| j=                  |      S )!a  
        cancel multiple orders
        :param str[] ids: order ids
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
        :param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NrW   rL   r^  r  client-order-idsclientOrderIdsz	order-ids)r^  r  r  r  z* cancelOrders() requires a symbol argumentr  client_order_ids,r5  )r  r  r  r  rO   r  r]  r<   r  r  r  r  )r  r  r  r   rb  rc  r   rN   z! cancelOrders() does not support rd  rU  )r>  r[  r?  r  r  strr  'spotPrivatePostV1OrderOrdersBatchcancelrg  r)   r<   r  joinr  rH  ri  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CCDKKPWY_D`aH~'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*
+#'#[#[\`\g\ghoqw\x#y+#'#X#XY]YdYdelntYu#v#'#T#TUYU`U`ahjpUq#r7*#'#`#`aealalmtv|a}#~+#'#]#]^b^i^ijqsy^z#{#'#Y#YZ^ZeZefmouZv#w	"&>#'#U#UVZVaVabikqVr#s+#'#R#RSWS^S^_fhnSo#p#'#N#Nt{{[bdjOk#lH%#'#U#UVZVaVabikqVr#s+#'#R#RSWS^S^_fhnSo#p#'#N#Nt{{[bdjOk#l"477-P#PS]#]`j#jkkh ~~h/''--r0  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   rH  )r=  r<   r   r4  r5  r^  )r=  r<   r   r  )	rA  r  r  r  rl  rm  r  rm  r  )r-  r  r  r  r  rp  rq  rB  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                    | j                          d}|| j                  |      }d}| j                  d||      \  }}i }d}|dk(  rQ||d   |d<   | j                  | j	                  ||            }| 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   rLd}| j                  d|      \  }}|dn|}|dk(  r|r#| j                  | j	                  ||            }nP|	r#| j                  | j	                  ||            }n+|
r#| j!                  | j	                  ||            }n| j#                  | j	                  ||            }n|dk(  r|r#| j%                  | j	                  ||            }n|	r#| j'                  | j	                  ||            }n|
r#| j)                  | j	                  ||            }nn| j+                  | j	                  ||            }nK|d   r'|d   r|r#| j-                  | j	                  ||            }n|	r"| j/                  | j	                  ||            }n|
r"| j1                  | j	                  ||            }n| j3                  | j	                  ||            }n|d	   r|r"| j5                  | j	                  ||            }n|	r"| j7                  | j	                  ||            }nd|
r"| j9                  | j	                  ||            }n@| j;                  | j	                  ||            }nt=        | j                  dz   |z   dz         | j                  |d      }| j?                  |      S )a  
        cancel all open orders
        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: *contract only* if the orders are trigger trigger orders or not
        :param boolean [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :param boolean [params.trailing]: *contract only* set to True if you want to cancel all trailing orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NrT   rL   r<   r]  rU  r=  z- cancelAllOrders() requires a symbol argumentrO   r  r  r  r  r  r  Fr  r   rb  rc  r   rN   z$ cancelAllOrders() does not support rd  ) r>  r[  r?  1spotPrivatePostV1OrderOrdersBatchCancelOpenOrdersrg  r  rm  r)   r<   r  rH  r  r  ri  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!MMdkkZaciNjkH >>(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*
+#'#^#^_c_j_jkrtz_{#|+#'#[#[\`\g\ghoqw\x#y!#'#\#\]a]h]hiprx]y#z#'#W#WX\XcXcdkmsXt#u7*#'#c#cdhdodopwy  eA  $B+#'#`#`aealalmtv|a}#~!#'#a#abfbmbmnuw}b~##'#\#\]a]h]hiprx]y#z	"&>#'#X#XY]YdYdelntYu#v+#'#U#UVZVaVabikqVr#s!#'#V#VW[WbWbcjlrWs#t#'#Q#QRVR]R]^egmRn#oH%#'#X#XY]YdYdelntYu#v+#'#U#UVZVaVabikqVr#s!#'#V#VW[WbWbcjlrWs#t#'#Q#QRVR]R]^egmRn#o"477-S#SV`#`cm#mnn >>(F3D++D11r0  r  c                     | j                          d|dkD  r| j                  |dz        ndi}| j                  | j                  ||            }|S )ad  
        dead man's switch, cancel all orders after the given timeout

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

        :param number timeout: time in milliseconds, 0 represents cancel the timer
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: the api result
        r  r   r  )r>  r  %v2PrivatePostAlgoOrdersCancelAllAfterrg  )r-  r  rJ  rh  rM  s        r/  cancel_all_orders_afterzhtx.cancel_all_orders_after=  sX     	Wq[t((48q
 ==dkk'SY>Z[ r0  r@  c                 P   | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |       |||| j	                  |      ||dS )Naddress
addressTagr@  noter  )r@  r  tagr  r  r=  )rA  r  r  check_addressr  )	r-  depositAddressr@  r  r  r  r  r  r  s	            r/  parse_deposit_addresszhtx.parse_deposit_addressX  s     "">9=~|<%%njA
%%j(;&&z8<7$$^W=	7#..y9"
 	
r0  r  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  ||d   gd      }| j                  |d      S )a  

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

        fetch a dictionary of addresses for a currency, indexed by network
        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `address structures <https://docs.ccxt.com/#/?id=address-structure>` indexed by the network
        r@  r<   rU  r  Fr  )r>  r@  %spotPrivateGetV2AccountDepositAddressrg  rH  parse_deposit_addressesindex_by)r-  r  rJ  r@  rh  rM  rU  parseds           r/  "fetch_deposit_addresses_by_networkz&htx.fetch_deposit_addresses_by_networkr  s     	==&
 ==dkk'SY>Z[ x4--dXf5E4FN}}VY//r0  c                     | j                          | j                  |      }| j                  |      \  }}| j                  ||      }| j	                  |d   ||      }||   S )a  
        fetch the deposit address for a currency associated with self account

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

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r  )r>  r@  handle_network_code_and_paramsr  )select_network_code_from_unified_networks)r-  r  rJ  r@  r  paramsOmitedindexedAddressesselectedNetworkCodes           r/  fetch_deposit_addresszhtx.fetch_deposit_address  so     	==&$($G$G$O!\BB4V"LLXV\M]_jl|} 344r0  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| 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 )	Nr@  r<   rU  r  Fr   r  r  )	r>  r@  &spotPrivateGetV2AccountWithdrawAddressrg  rH  r  rl  rm  r  )r-  r  r  r  rJ  r@  rh  rM  rU  allAddresses	addressesrq  r  	noteMatchnetworkMatchs                  r/  fetch_withdraw_addresseszhtx.fetch_withdraw_addresses  s    ==&
 >>t{{7TZ?[\ x433D8F;K:LeT	q#l+, 	*A"1oGC76?d+BI'4/WWY5G;5VL\  )	* r0  c                     ||dkD  rd}| j                          d}|| j                  |      }dddd}||d   |d<   |||d	<   | j                  | j                  ||            }| j	                  |d
   |||      S )a&  

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

        fetch all deposits made to an account
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        NrB   r  nextr   rT  directr  r<   r@  r[  rU  r>  r@  $spotPrivateGetV1QueryDepositWithdrawrg  parse_transactionsr-  r  rR  r  rJ  r@  rh  rM  s           r/  fetch_depositszhtx.fetch_deposits  s     =ECKE}}T*H

 "*4.GJ#GFO<<T[[RX=YZ6 &&x'75%PPr0  c                     ||dkD  rd}| j                          d}|| j                  |      }dddd}||d   |d<   |||d	<   | j                  | j                  ||            }| j	                  |d
   |||      S )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<   r@  r[  rU  r,  r/  s           r/  fetch_withdrawalszhtx.fetch_withdrawals  s     =ECKE}}T*H

 "*4.GJ#GFO<<T[[RX=YZ2 &&x'75%PPr0  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 )#Nr2  r@  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)r@  r}  rate)commentinternalrZ  )r  r  rA  r7   
string_absrl  r  r  r  ra  parse_transaction_statusr,  )r-  r3  r@  r  r  rT  rL  r  txHashr3  r?  s              r/  parse_transactionzhtx.parse_transaction2  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  rH  )unknown
confirming	confirmedsafeorphanrL  rH  	reexaminerejectpasszwallet-rejectzconfirm-errorrepealedzwallet-transferzpre-transferrT  rU  s      r/  rA  zhtx.parse_transaction_status  sO      #"""%% (%%
( &&99r0  r  c                 >   | j                  ||      \  }}| j                          | j                  |       | j                  |      }||d   j	                         d}|||d<   d}| j                  |      \  }}|| j                  ||      |d<   t        | j                  |||            }| j                  | j                  di       }	| j                  |	dd      r| j                  |d	      }
|
s| j                         }| 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/                  ||            }| j1                  ||      S )a  

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

        make a withdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r<   )r  r@  Nz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  r@  r  r  r  floatcurrency_to_precisionrH  r  r  ra  r  r(  
currenciesr)   r<   r  r  r7   
string_sub$spotPrivatePostV1DwWithdrawApiCreaterg  rC  )r-  r  rw  r  r  rJ  r@  rh  r  withdrawOptionsrZ  rS  targetNetwork	feeStringrJ  amountSubtractedStringamountSubtractedrM  s                     r/  r   zhtx.withdraw  s&    99#vFV7#==& ,,.
 ?"%GJ"AA&IV"#66{DIGGt11$LM//$,,
BG>>/<?""651C{!224
"&"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"<<T[[RX=YZ %%h99r0  r   c           
      b    | j                  |d      }| j                  d |      }||d d |d d d d d	S )NrU  )	r=  r<   r  rQ  r@  rw  fromAccount	toAccountr   )rA  r  )r-  r   r@  r<   r  s        r/  parse_transferzhtx.parse_transfer  sM     h/&&tX6

 
	
r0  r\  r]  c                    | j                          | 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}|rC|	d
z   |
z   }| j                  |d|      }||d<   | j                  | j                  ||            }n,|r%|r#| j                  | j                  ||            }n|r$|r"| j                  | j                  ||            }n|r)|r'|
|d<   | j                  | j                  ||            }n|r)|r'|	|d<   | j!                  | j                  ||            }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                  ||            }| j)                  ||      S )a  
        transfer currency internally between wallets on the same account

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

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from 'spot', 'future', 'swap'
        :param str toAccount: account to transfer to 'spot', 'future', 'swap'
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.symbol]: used for isolated margin transfer
        :param str [params.subType]: 'linear' or 'inverse', only used when transfering to/from swap accounts
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r<   r@  rw  Nr   rb  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>  r@  rQ  rR  r  convert_type_to_accountin_arrayr  r*   r<   rA   spotPrivatePostV1FuturesTransferrg   privatePostCrossMarginTransferIn!privatePostCrossMarginTransferOutprivatePostDwTransferInMarginprivatePostDwTransferOutMarginr  ro  v2PrivatePostAccountTransferr^  )r-  r  rw  r\  r]  rJ  r@  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<<T[[RX=YZH'<<T[[RX=YZH6==dkk'SY>Z[H* +GH99$++gv:VWHf -GH::4;;wPV;WXH("!V+1M$1M"/K))&(;684%!^^F3F06G,-06G,-(0fmGFO&,F+GDM88Wf9UVH ""8X66r0  c                     | j                          | j                  |      }| j                  |dg       }| j                  |      S )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>`
        rU  )r>  spotPrivateGetV1MarginLoanInforH  parse_isolated_borrow_ratesr  s       r/  fetch_isolated_borrow_rateszhtx.fetch_isolated_borrow_ratesH  sE     	66v>< x4//55r0  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]  rS  r   r   r@  zactual-ratei \&)	r]  r  baseRater  	quoteRater}  r  rQ  r=  )rA  r`  rH  r  ra  )
r-  r=  r[  rb  r]  rS  baseData	quoteDatar  r  s
             r/  parse_isolated_borrow_ratezhtx.parse_isolated_borrow_rates  s    0 ##D(3!!(F3__T<<
??:q1OOJ2	!!(J7""9j9++F3((=A,,W5)))]C

 
	
r0  c                    |t        | j                  dz         d}| j                  |dd      \  }}|r| j                  d||||dddd		      S | j	                          | j                  |      }d
|d   i}d}|d   r"| j                  | j                  ||            }n?|d   r"| j                  | j                  ||            }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 )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~   rZ  
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  rt  ru  )r-  r]  rR  r  rJ  rZ  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&334MvW\^cekmy  |J  LM  OQ  R  RV$VD\
 )OOPTP[P[\cekPlmHHUUVZVaVabikqVrsH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Xr0  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   rT  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86400000rT  )r-  r  	intervalss      r/  r  zhtx.parse_funding_interval  s/    
	 	8X>>r0  c                 l   | j                          | j                  |      }d|d   i}d}|d   r"| j                  | j                  ||            }n?|d   r"| j	                  | j                  ||            }nt        | j                  dz         | j                  |di       }| j                  ||      S )a  
        fetch the current funding rate

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r  r<   Nr   r   z: fetchFundingRate() supports inverse and linear swaps 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\
 )EEdkkRY[aFbcHHKKDKKX_agLhiHtww)eeff  626&&vv66r0  c                 .   | j                          | j                  |      }| j                  | j                  dd      }d}| j	                  |dd|      \  }}|.| j                  |d      }| j                  |      }|d   }|rdnd}i }d}	|dk(  r"| j                  | j                  ||            }	n?|dk(  r"| j                  | j                  ||            }	nt        | j                  dz         | j                  |	d	g       }
| j                  |
|      S )
a#  
        fetch the funding rate for multiple markets

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

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexed by market symbols
        r  r   Nr   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_ratesH  s+    	%%g.))$,,8H(S77@SU^`no**7A6K[[-Fh'H"*h	G
 hPPQUQ\Q\]dflQmnH	!JJ4;;W^`fKghHtww)\\]]& x4''g66r0  c                    | j                          d}| j                  d|      \  }}|dn|}i }|| j                  |      |d<   |||d<   d}d}	|dk(  r=|| j                  |      }|d   |d<   | j	                  | j                  ||            }	n<|| j                  |      }
|
d   |d	<   | j                  | j                  ||            }	| j                  |	d
      }| j                  ||      }| j                  ||||      S )a  
        fetch the interest owed by the user for borrowing currency for margin trading

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

        :param str code: unified currency code
        :param str symbol: unified market symbol when fetch interest in isolated markets
        :param int [since]: the earliest time in ms to fetch borrrow interest for
        :param int [limit]: the maximum number of structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
        Nrk   rb  z
start-dater[  rc  r<   r]  r@  rU  )r>  ri  yyyymmddr[  privateGetMarginLoanOrdersrg  r@  privateGetCrossMarginLoanOrdersrH  parse_borrow_interestsfilter_by_currency_since_limit)r-  r  r]  rR  r  rJ  r  rh  r[  rM  r@  rU  interests                r/  fetch_borrow_interestzhtx.fetch_borrow_interest|  s/    	
!??@UW]^
F!+!3W*
$(MM%$8GL!#GFO#!V,$*4L!66t{{7F7STH==.&.tn
#;;DKKQW<XYH. x0..tV<228T5%PPr0  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]  rb  rc  z
accrued-atr@  zinterest-amountzinterest-ratezloan-amount)	r=  r]  r@  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
HmacSHA256rM  )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  cancelrB  r  zorders/placer^  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  rl  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   errorrZ  rY  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_errorse  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                 <   | j                          | j                  |      }| j                  d||      \  }}ddi}|||d<   d}	|dk(  r|d   |d<   |d	   rUd}
| j                  d|      \  }
}|
d
n|
}
|
dk(  r	|d   |d<   n|d   |d<   | j	                  | j                  ||            }	nK| j                  | j                  ||            }	n)|d   |d<   | j                  | j                  ||            }	| j                  |	dg       }| j                  ||||      S )a  
        fetch the history of funding payments paid and received on self account

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

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        r|   rT  z30,31N
start_daterN   r<   r   r   rb  rc  mar_acctr  r]  rU  )
r>  r[  r?  ri  :contractPrivatePostLinearSwapApiV3SwapFinancialRecordExactrg  4contractPrivatePostSwapApiV3SwapFinancialRecordExact4contractPrivatePostApiV3ContractFinancialRecordExactr  parse_incomes)r-  r]  rR  r  rJ  r[  rK  r  rh  rM  r  rU  s               r/  fetch_funding_historyzhtx.fetch_funding_history  se    	V$ >>?TV\^de
EG
 $)GL!"(,GJh. "
%)%G%GH]_e%f"
F)3);W*
+*0,GJ'*0*;GJ'ZZ[_[f[fgnpu[vw,  TTUYU`U`ahjoUpq &tGHPPQUQ\Q\]dfkQlmH~~h3!!$u==r0  r  c                    |t        | j                  dz         | j                          | 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                  ||            }|S |	dk(  r#| j                  | j                  ||            }|S t        | j                  dz         |dk(  r#| j                  | j                  ||            }|S |dk(  r#| j                  | j                  ||            }|S t        | j                  dz         )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   rb  rc  + setLeverage() not support self market typerN   )r)   r<   r>  r[  r?  ri  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'UUVZVaVabikpVqrN M w&ZZ[_[f[fgnpu[vwJ G #477-Z#Z[[ X%OOPTP[P[\cejPkl* ) v%OOPTP[P[\cejPkl& # #477-Z#Z[[r0  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]  r`  r  	cost_openposition_marginr  rr  longshortprofit_unrealmargin_moder  profit_rater  
last_pricer   rb  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           
         | j                          | 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(  rF|dk(  r| j                  |      }	nu|dk(  r| j                  |      }	n^t        | j                  d	z         |dk(  r| j                  |      }	n/|d
k(  r| j                  |      }	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 )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   rb  r   rL   rO   rc  z. fetchPositions() not support self market typerN   rU  r6  r  rQ  r]  F)r>  r
  rm  rA  r[  ri  r  r?  2contractPrivatePostLinearSwapApiV1SwapPositionInfo7contractPrivatePostLinearSwapApiV1SwapCrossPositionInfor/   r<   ,contractPrivatePostApiV1ContractPositionInfo,contractPrivatePostSwapApiV1SwapPositionInforH  r  rl  r/  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  s     	%%g.LMq ((!4U+
!??@PRXZab
F99:JFTZ\de
!??@PRXZ`a
F!JhZ'RRSYZw&WWX^_"477-]#]^^: X%LLVTv%LLVT"477-]#]^^f x4%%h5	q#d)$ 	AAwH((2FMM$++f& LL3/  	 --fhOOr0  c                 z   | j                          | 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   rf|dk(  r"| j	                  | j                  ||            }n|dk(  r"| j                  | j                  ||            }n~t        | j                  dz         |dk(  r"| j                  | j                  ||            }n?|dk(  r"| j                  | j                  ||            }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 )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   rb  rO   r   r  r]  r  r  r<   r  r   rc  z- fetchPosition() not support self market typerN   r  rU  r   	positionsr6  r  rQ  )r>  r[  ri  r?  9contractPrivatePostLinearSwapApiV1SwapAccountPositionInforg  >contractPrivatePostLinearSwapApiV1SwapCrossAccountPositionInfor/   r<   3contractPrivatePostApiV1ContractAccountPositionInfo3contractPrivatePostSwapApiV1SwapAccountPositionInforH  r  rl  rm  r  r/  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'YYZ^ZeZefmotZuvw&^^_c_j_jkrty_z{"477-\#\]]n X%SSTXT_T_`ginTopv%SSTXT_T_`ginTop"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r0  c                 J    ddddddddddddddd	}| j                  |||      S )
Nr0  rZ  r   creditr  r5  exchangerebate)r0  etfztransact-feezfee-deductionr   rB  liquidationr  r  r   zwithdraw-feerC  zother-typesrD  rT  )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 )	Nr@  
transactIdtransferTypetransactTimer  r  transactAmt)r=  r<   r  r  referenceIdreferenceAccountrT  r@  rw  r  rQ  beforeafterr   rZ  )rA  r  r  r  safe_ledger_entryrG  ra  r  )	r-  rH  r@  r  r  r<   rK  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                    | j                          d}| j                  |dd      \  }}|r| j                  d||||d      S | j                  ddd|      }d|i}d}|| j	                  |      }|d   |d	<   |||d
<   |||d<   | j                  d||      \  }}| j                  | j                  ||            }	| j                  |	dg       }
| j                  |
|||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

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

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        Fr   rZ  r  rL   Nr  r<   r@  	startTimer  endTimerU  )
r>  r  rf  r  r@  rg  spotPrivateGetV2AccountLedgerrg  rH  parse_ledger)r-  r  rR  r  rJ  rZ  r  rh  r@  rM  rU  s              r/  fetch_ledgerzhtx.fetch_ledgerU  s    	88PZ[&44]D%QVX^`cdd11&$fM		
 }}T*H"*4.GJ#(GK $GG229gvN55dkk'66RSB x4  x>>r0  c                     | j                          | j                  |      }| j                  |dg       }| j                  ||d      S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
        rU  r  )r>  0contractPublicGetLinearSwapApiV1SwapAdjustfactorr  parse_leverage_tiers)r-  re  rJ  rM  rU  s        r/  fetch_leverage_tierszhtx.fetch_leverage_tiers  sI     	HHP< ~~h3((wHHr0  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]  r@  minNotionalmaxNotionalmaintenanceMarginRatemaxLeverager=  )rA  r  rl  rm  r  r  r`  r  ra  r,  r7   r  )r-  r=  r[  r  rb  tiersbracketsrq  rH  r  r`  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                    |dk7  r'|dk7  r"|dk7  r|dk7  rt        | j                  dz         | j                          dddd	d
}| j                  |      }| j	                  |ddd      }||   |d}	|||	d<   d}
|d   rB| j                  |d   d      |	d<   |d   |	d<   | j                  | j                  |	|            }
ne|d   r7d|	d<   |d   |	d<   |d   |	d<   | j                  | j                  |	|            }
n)|d   |	d<   | j                  | j                  |	|            }
| j                  |
d      }| j                  |d      }| j                  ||||      S )u  
        Retrieves the open interest history of a currency

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

        :param str symbol: Unified CCXT market symbol
        :param str timeframe: '1h', '4h', '12h', or '1d'
        :param int [since]: Not used by huobi api, but response parsed by CCXT
        :param int [limit]: Default：48，Data Range [1,200]
        :param dict [params]: Exchange specific parameters
        :param int [params.amount_type]: *required* Open interest unit. 1-cont，2-cryptocurrency
        :param int [params.pair]: eg BTC-USDT *Only for USDT-M*
        :returns dict: an array of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
        r   r   12hr   zJ fetchOpenInterestHistory cannot only use the 1h, 4h, 12h and 1d timeframer   r   12hourr   )r   r   rp  r   amount_type
amountTyper  )r}  rr  Nr[  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  rR  r  rJ  r   r[  rs  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II$++V]_eJfgHH'-GO$'-d|GO$'-d|GO$OOPTP[P[\cekPlmH'-d|GO$II$++V]_eJfgHz x0~~dF+00vueLLr0  c                 N   | j                          | j                  |      }d}|3t        |      }|dkD  r#| j                  |d      }| j	                  |      }i }d}| j                  d||d      \  }}d}| j                  d||      \  }}d}	|dk(  r"| j                  | j                  ||            }	nM|dk(  r"| j                  | j                  ||            }	n&d|d<   | j                  | j                  ||            }	| j                  |	d	g       }
| j                  |
|      S )
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[  r7  ri  rh  r3  rK  rM  rU  s              r/  fetch_open_interestszhtx.fetch_open_interestsS  sE    	%%g.LMq ((!4U+99:JFTZ\de
!??@PRXZ`a
F!FFt{{SZ\bGcdH& 	!FFt{{SZ\bGcdH& (.GO$LLT[[Y`bhMijH. ~~h3((w77r0  c                    | j                          | j                  |      }|d   st        | j                  dz         |d   rt	        | j                  dz         d|d   i}d}|d   rB| j                  |d	   d
      |d
<   |d   |d<   | j                  | j                  ||            }nM|d   r'd|d
<   | j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }| j                  |d   |      }| j                  |d      }||d<   | j                  |      |d<   |S )a=  
        Retrieves the open interest of a currency

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

        :param str symbol: Unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
        r   z3 fetchOpenInterest() supports contract markets onlyrP   z> fetchOpenInterest() does not currently support option marketsr  r<   NrO   r=  r  r  r]  r   rN   rU  r   r6  r  rQ  )r>  r[  r*   r<   r/   rA  rz  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  sl    	V$j!TWW'\\]](tww)iijjVD\
 ('+'7'7v'XGO$ &x 0GHFFt{{SZ\bGcdHH'-GO$LLT[[Y`bhMijH FFt{{SZ\bGcdH| x4//Q@%%h5	$-[!#'<<	#:Z r0  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j	                  ||      |||||| j                  |      |d|      S )Nr6  r`  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                 .   | j                          | j                  |      }| j                  |      }|d   | j                  ||      |d   d}| j	                  | j                  ||            }| j                  ||      }	| j                  |	||d      S )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>`
        r<   )r@  rw  r]  rw  r]  )r>  r@  r[  rR  privatePostMarginOrdersrg  parse_margin_loan)
r-  r]  r  rw  rJ  r@  r[  rh  rM  r3  s
             r/  borrow_isolated_marginzhtx.borrow_isolated_marginZ   s     	==&V$ 00v>Tl

 //GV0LM ,,Xx@{{;)
  	r0  c                    | j                          | j                  |      }|d   | j                  ||      d}| j                  | j	                  ||            }| j                  ||      }| j	                  |d|i      S )a
  
        create a loan to borrow margin

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

        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r<   r`  rw  )r>  r@  rR  privatePostCrossMarginOrdersrg  r  )r-  r  rw  rJ  r@  rh  rM  r3  s           r/  borrow_cross_marginzhtx.borrow_cross_margin}   s     	==& 00v>
 44T[[&5QR ,,Xx@{{;f)
  	r0  c                 x   | j                          | j                  |      }| j                  dd||      }|d   | j                  ||      |d}| j	                  | j                  ||            }| j                  |dg       }	| j                  |	d      }
| j                  |
|      }| j                  |||d      S )a  
        repay borrowed margin and interest

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

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

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

        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rL   rb  Nr<   r  r  r   rw  r  )r-  r  rw  rJ  r@  r  rh  rM  rU  r  r3  s              r/  repay_cross_marginzhtx.repay_cross_margin   s     	==&11&'4P	 00v>"

 55dkk'66RS x4tQ',,T8<{{;f)
  	r0  c                     | j                  |d      }| j                  |dd      | j                  d |      d d || j                  |      |dS )N	repayTimerepayIdrU  )r<   r@  rw  r]  r  rQ  r=  )r  r  r  r  )r-  r=  r@  r  s       r/  r  zhtx.parse_margin_loan   sZ    , %%dK8	$$T9f=//h?"Y/
 	
r0  c                 n   |t        | j                  dz         | j                  |d      }| j                  |dg      }| j	                  |      }i }|d   r	|d   |d<   n|d   |d<   |||d	<   |||d
<   |||d<   d}|d   rI|d   r"| j                  | j                  ||            }nC| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |d      }	| j                  |	d      }
| j                  |
|      }| j                  |d      S )u  
        Fetches historical settlement records

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

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

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

        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fees structures <https://docs.ccxt.com/#/?id=fee-structure>`
        rU  r@  )r>  r  r  parse_deposit_withdraw_fees)r-  r  rJ  rM  rU  s        r/  fetch_deposit_withdraw_feeszhtx.fetch_deposit_withdraw_feesn!  sH     	::6BJ ~~h///eZHHr0  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  r@  r  rp  rv  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_timer1  )rl  rm  rH  r  r  parse_settlementr  rg  )r-  r  r[  rp  rq  
settlementr  r  timestampDetailsrv  rH  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                 J   | j                          | j                  |      }| j                  |dd      }d|i}|||d<   | j                  d||      \  }}d}|d   rQ|d   |d<   |d	   r"| j	                  | j                  ||            }nr| j                  | j                  ||            }nP|d
   r*|d   |d<   | j                  | j                  ||            }n!t        | j                  dz   |d   z   dz         | j                  |dg       }	| j                  |	|||      S )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>`
        r^  r   Nr_  r`  rN   r<   r   r   rO   r]  z& fetchLiquidations() does not support rT  r0  rU  )r>  r[  r  rg  5contractPublicGetLinearSwapApiV3SwapLiquidationOrdersrg  /contractPublicGetSwapApiV3SwapLiquidationOrders/contractPublicGetApiV3ContractLiquidationOrdersr/   r<   r  parse_liquidations)
r-  r]  rR  r  rJ  r[  	tradeTyperh  rM  rU  s
             r/  fetch_liquidationszhtx.fetch_liquidations9"  sO     	V$%%flA>	)
 $)GL!22:wO&>"(,GJhUUVZVaVabikqVrsOOPTP[P[\cekPlmH &tGHKKDKKX_agLhiHtww)QQTZ[aTbbennoo0 ~~h3&&tVUEBBr0  c                 ^   | j                  |d      }| j                  |d      }| j                  || j                  ||      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      || j                  |      d	      S )	Nr  r3  r`  r  r  rw  r:  )	r=  r]  r  r  r  	baseValue
quoteValuer  rQ  )rA  r  safe_liquidationr`  ra  r  )r-  rF  r[  rb  r  s        r/  parse_liquidationzhtx.parse_liquidationx"  s    " ##KA%%k<@	$$&&x8))+x@ ,,V^D%%k7;))+x@**;8HI"Y/
&
 
 
	r0  c                     | j                          | 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
   rI|d   r"| j                  | j                  ||            }n| j                  | j                  ||            }n`d}	| j                  d|d      \  }	}|	dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j!                  ||      S )a  
        closes open positions for a contract market, requires 'amount' in params, unlike other exchanges

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

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

 EXCHANGE SPECIFIC PARAMETERS
        :param number [params.amount]: order quantity
        :param str [params.order_price_type]: 'lightning' by default, 'lightning_fok': lightning fok type, 'lightning_ioc': lightning ioc type 'market' by default, 'market': market order type, 'lightning_fok': lightning
        :returns dict: `an order structure <https://docs.ccxt.com/#/?id=position-structure>`
        r  r   z6 closePosition() symbol supports contract markets onlyrY   r   r<   )r  r  Nr  r   r`  rw  zP closePosition() requires an extra argument params["amount"] for inverse markets)r  r`  rw  rN   rb  )r>  r[  rA  r*   r<   check_required_argumentr  r)   r  r  6contractPrivatePostSwapApiV1SwapLightningClosePositionrg  .contractPrivatePostApiV1LightningClosePositionri  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~VVW[WbWbcjlrWstNNt{{[bdjOklJ!%!C!COU[]d!eJW$aabfbmbmnuw}b~\\]a]h]hiprx]yz&11r0  r  c                    | j                          |rdnd}d}|| j                  |      }d}| j                  d|d      \  }}d|i}d}||d   rt        | j                  dz         |d	k(  rE|t        | j                  d
z         |d   |d<   | j                  | j                  ||            }|S d|d<   | j                  | j                  ||            }|S )a  
        set hedged to True or False

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

        :param bool hedged: set to True to for hedged mode, must be set separately for each market in isolated margin mode, only valid for linear markets
        :param str [symbol]: unified market symbol, required for isolated margin mode
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: "cross"(default) or "isolated"
        :returns dict: response from the exchange
        	dual_sidesingle_sideNr   rb  position_moder   z4 setPositionMode can only be used for linear marketsrc  zD setPositionMode requires a symbol argument for isolated margin moder<   r  r  )	r>  r[  ri  r*   r<   r)   8contractPrivatePostLinearSwapApiV1SwapSwitchPositionModerg  =contractPrivatePostLinearSwapApiV1SwapCrossSwitchPositionMode)	r-  r  r]  rJ  posModer[  r  rh  rM  s	            r/  set_position_modezhtx.set_position_mode"  s    	!'+][[(F
!??@QSY[bc
FW
 VI%6TWW']]^^#~'2x(xyy(.tG$%TTUYU`U`ahjpUqrH8  )/G$%YYZ^ZeZefmouZvwH r0  )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   r/  r    rQ  rU  rT  rn  rw  r  r{  r  r   r  r  r  r	   r  r  r  r   r  r  r  r  r  r  r,  r.  r   r1  r3  rF  rW  r  rQ  rt  r   r   r   rx  r  r  rs  r   r  r  r  r  r  r  r
   r  r   r  r   r'  r"   r0  r2  rC  rA  r   r#   r^  r   r   ru  r   r{  r  r   r  r  r  r   r  r   r  r  r)  r  intr  r  r
  r  r/  r   r8  r@  rG  r   rS  rY  r   r]  r   rn  rx  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 
( 57 !5 !5;N !5F 7;2 G  :< PS P@ :>b 
3 
4x $&  $v,  D RT Zs ZS Zx  3   D]4 ] ]6 ]~ 02 N3 Nf N` 04B hHW hH7 hHT 48 c5 c5J
f 
  :>b Trs Tr3 TrY TrlA Av A AF 9=4^bkm NS N# NS NX[ N, >BPTcgpr G# Gs G# G]` G* -1tRV_a Y?c Y? Y?C Y?v 6:UW HY3 HYs HY# HY\`af\g HYT
 
4 
, 26DW[df H# Hc HQT Hkoptku HB %' )4= ).
& EIX\eg #6S #6c #6RU #6J ') qZ qfAC Ac AQc Q Q $& p( pd	 26b H'c H'3 H'T
 AESWfjsu A=# A=S A=`c A=F /3TXac Y Y3 Yc Y 6:[_hj rs r# rUX r 37TX\eg [?C [?s [?RU [?z :>D_cln ^3 ^c ^Y\ ^ *.Dt\^ !H3 !Hc !H !Hcghmcn !HF 154VZce  S#  SS  SPS  Sjnotju  SD /3TXac [? [?3 [?c [?hlmrhs [?z: :*j jv j jX RT N N5 N$ x|  NR  im  vx LC Ly LPY Lch Lqt L  }B L* tx  AC f, f,9 f,I f,_d f,mp f,P x|  EG U,C U,y U,PY U,ch U,qt U,n gksu `03 `0i `0y `0RW `0`c `0D @B r1D$6 r1h 37r ys yC yv 04B R. R.h4l /32 s2 s2j <> s 6
h 
4 DF 0s 0$~J^ 0B 79 5# 5^ 5" 8<VX S @ *.Dt\^ 6Q3 6Qc 6Q 6Qcghsct 6Qp -1tRV_a 4Qc 4Q 4QC 4Qfjkvfw 4QlZ
T Z
X Z
Q\ Z
x:s :. DHPR 6:S 6:% 6:# 6:Wb 6:p
t 
x 
= 
. [] R7S R7% R7c R7c R7an R7h 24 )68K )6V)
t )
V )
Oa )
V 8<$]ajl HY HYC HYWZ HYT+
6 +
[ +
Z? 68 '7 '7K '7R 6:" 277 27 27h 15DW[jnwy ;Q# ;Qc ;QQT ;Qdg ;Q  C  DR  S ;Qz9
$ 9
 9
. 9
vD &eBSW lP\c 3 S # X\ dg B 37TX\eg R>C R>s R>RU R>h 9=R GS G# GR
6 
8Xt XV Xt 26b FPw FPT(^ FPP 24 xS xt3&%t %x %; %N (,$TZ\ I? I?C I?s I?aefqar I?V 7;2 'IG 'I- 'IR $|J\ 0 BFTXgktv pM# pMc pMad pMd 7;2 [8G [8z 79 d# dLBF BH TV !S ! !U !F DF  U @ LN &C &s &P <> $s $L
 
B 6:[_hj `6s `6# `6UX `6D <@ 1I 1If= =~5n 
D <@d[] =C =CS =C =C~V > =A 32S 32	 32PU 32j =A : :c :r0  r9   )>ccxt.base.exchanger   ccxt.abstract.htxr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   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    ( )  @  @  @  @  @  @  @  @  @  * 0 - . . ' & . ) * ) , . 1 * + 3 4 %fK(K fKr0  