
    ie                       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 d dlmZ d dlmZ d dlmZ d dlmZ d d	lm Z  d d
lm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dlm)Z) d dlm*Z* d dlm+Z+ d dlm,Z, d dl-m.Z. d dl-m/Z/ d dl0m1Z1  G d dee          Z2dS )    )Exchange)ImplicitAPIN)AccountBalances
CurrenciesCurrencyIntMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypeStrStringsTickerTickers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                   r    e Zd Z fdZi fdZi fdZdd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Zde	fdZdd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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'Z+i fde,fd(Z-d fd)	Z.d fd*	Z/i fde0fd+Z1di fde	defd,Z2d- Z3dddi fdededefd.Z4dddi fdededefd/Z5dddi fdededefd0Z6dddi fdededefd1Z7dddi fdededefd2Z8dddi fdedededee9         fd3Z:dddi fdedededee9         fd4Z;dddi fdedededee9         fd5Z<d6 Z=ddede9fd7Z>i fde	d8e?fd9Z@dddi fde	d:eAd;eBd<e?d=eCde9fd>ZDdi fde	d:eAd;eBd<e?d=eCf
d?ZEdi fde	d:eAd;eBd<e?d=eCf
d@ZFdi fde	d:eAd;eBd<e?d=eCf
dAZGi fdBeeH         fdCZIdi fde	defdDZJdi fdefdEZKdi fdefdFZLddGeMfdHZNi fdIe	fdJZOi fdIe	fdKZPddi fdIe	fdLZQdddi fdIedededeeR         fdMZSdddi fdIedededeeR         fdNZTddGeMdeRfdOZUdP ZVdi fdIe	d<e?fdQZWddGeMfdRZXi fdIe	d<e?dSe	dTe	deYf
dUZZi fdVZ[ddefdWZ\dddi fdededefdXZ]ddefdYZ^i fde	fdZZ_di fd
efd[Z`ddddi fdIedededefd\Zaddefd]Zbd^d_i ddfd`Zcda Zddddi fdededefdbZedi fdcedefddZfddefdeZgddefdfZhdi fd
efdgZii fde	fdhZjdi ZkddGeMfdjZldddi fdIededefdkZmdi fd
efdlZni fde	fdmZodd
efdnZpdoddi fde	dedefdpZqi fde	fdqZrddefdrZsi fde	dIe	d<e?fdsZti fdIe	d<e?fdtZui fde	dIe	fduZvi fdIe	fdvZwddGeMfdwZxdddi fdededefdxZydi fdyefdzZzddGeMfd{Z{d| Z|d} Z}ddi fde	dedefd~Z~ddefdZdi fdedefdZ xZS )htxc                     |                      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@dAddBddCddDddEddFddGd"i dHddId dJddKddLd dMd"dNddOddPd"dQddRddSddTd"dUddVddWddXdi dYd dZdd[dd\dd]d d^dd_dd`ddaddbd"dcddddded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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|                     dl          |                     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"          dddt$          di dRdddddidV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+d,d,d-d-d.d.d/d/i d0d0d1d1d2d2d3d3d4d4d5d5d6d6d7d8d9d9d:d;d<d=d>d>d?d?d@d@dAdAdBdBdCdCi dDdDdEdEdFdFdGdGdHdHdIdJdKdKdLdLdMdMdNdNdOdOdPdPdQdQdRdRdSdSdTdTdUdUi dVdVdWdWdXdXdYdYdZdZd[d[d\d\d]d]d^d^d_d_d`dadbdbdcdcdddddededfdfdgdgdhdidjdkdldmddndodpddqidrdddsdtdudddvdwdxdydz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i          S (  Nidr.   nameHTX	countriesCN	rateLimitd   	userAgent	chrome100	certifiedTversionv1hostnamezapi.huobi.proprohasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostF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fetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositions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)r@   rC   rB   )contractr@   statuszhttps://{hostname})r   r   r@   publicprivatev2Public	v2Privatezhttps://www.huobi.comz^https://www.huobi.com/en-us/v/register/double-invite/?inviter_id=11343840&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   r@   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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 symbolzsymbol trade not open now)z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types)r@   r   r   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)r@   fundingrC   accountsByIdotcpointsuper-margin
investmentborrowgrid-tradingdeposit-earningotc-options)
r@   rA   r  r  r  r  r  r  r  r  typesByAccount)r=   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commonCurrenciesThemiszGame.comHitChainPentazSuper Bitcoin	SoulsaverzBitcoin File)GETGTCHITPNTrL  SOULrM  )deep_extendsuperr.   describe
userAgentsparse_numberr(   r   r   r   r    r#   r"   r!   r   r)   r'   r&   r+   )self	__class__s    N/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/htx.pyr  zhtx.describe"   sr4   c4 0 0 9 9 ; ; {>
%{>
E{>
 ${>
 	{>

 5{>
 {>
 t{>
 {>
 4{>
  jjj $j 	j
 $j $j Tj $Tj 'j "4j tj j 'j /j ,Uj  0!j" t#j j$ %j& ('j( ')j* &t+j, (-j. "4/j0 (1j2 -d3j4 %d5j6  7j8 9j:  ;j< &t=j> +D?j@ )$AjB &tCjD #DEj j jF $TGjH 'IjJ (KjL "4MjN OjP &tQjR (SjT 1$UjV  WjX *:YjZ +D[j\ &t]j^ #D_j` *4ajb $Tcjd "4ejf *5gj j jh +Dijj #Dkjl "4mjn tojp #Dqjr  sjt %dujv $Twjx /yjz +D{j| }j~ !$j@ &uAjB  CjD dEjF $TGjH +DIj j jJ !$KjL "4MjN dOjP !$QjR "4SjT tUjV #DWjX  YjZ !$[j\ %e]j^ )$_j` )$ajb tcjd tejf gjh Tijj tkj j jl "4mjn #Eojp %dqjr &tsjt 'ujv $Twjx !$yjz )${j| "4}j~ #Dj@ +DAjB CjD #DEjF &tGjH tIjJ  KjL "4Mj jN   Sj j j{>
j  k{>
B  ~ .+ 7'A&I# #
 (D&I! !
 
 & 3 4023 4!5  /{ $    ;]/ /C{>
b  01)* (!0! 3A 21	
 ,Q 6q 23 ( -a .q 0 3A 1! ' #A  .q!" .q#$ 12&'%&,-)*'()*,-+,)*%&9  <*A+Q )! .q	
 ,Q 3A 3A 6q 8 4Q / &q 7 3A $Q  +A!" )!#$ *+()()*+35,./  ?8 8t *+,-,-+,./ *C7 5a *1	
 1! +A +A +C ' ,S 9# 6s ( -a  1!!$ -c%& 23'( 569:*+)*5756-.5  8*A*A -c -c	
 ? =c 9# 3C 1! :1  0!" 1"#$ (%& 3B'( 3A)* 4Q+, .q-. ;<01,.3  ;8 8@ ! 5q$! !&$91("( !&$91("'# # !&$91("( !&$91("'! !%  F   . /  21  <Q	 
 6q  21  1!  8  ;A  9!  9!  @  5a  3A   3A! " -a# $ ,Q% & -.,-45*+01013     <7 137  G7  3A	7 
 9#7  1!7  07  /7  9!7  87  :17  6q7  87  @7 " .q#7 $ *1%7 & 4Q'7 ( 5a)7  7 * 7+7 , :1-7 . 8/7 0 ;B17 2 <Q37 6 2377 8 9#97 : =c;7 < Ec=7 > Fs?7 @ .sA7 B /C7 D 4QE7 F =aG7 J 5aK7 L 5aM7 N 6qO7  7 R 4558:=9:;<@A4545<=3423,-m7  7  7 p1!111! 211! 0	1!
 211! 81! J11! 6q1! 3A1! 5a1! :11! :11! =a1!  ?!1!" ;A#1!$ 22%1!& :2'1!* 4S+1! 1!, 4S-1!. 23/1!0 Fs11!2 Fs31!4 DS51!6 :371!8 >q91!< -a=1!> :1?1!B 3AC1!D 7E1!F 8G1!H /I1!J @K1!L :1M1!N ;AO1!P 5aQ1! 1!R HI78/012:<35a1! 1! 1!sk  k =J JZ  g .g (!g  <Q	g 
 4Qg  =ag  :1g  <Qg  =ag  +Ag  )!g  3Ag  DQg  3Ag  9!g   <Q!g " +A#g $ 3A%g  g & 8'g ( =a)g * ;A+g , @-g . <Q/g 0 81g 2 B13g 4 CA5g 6 A!7g 8 A!9g : 9!;g < 9!=g > I!?g @ A!Ag D =aEg F 5aGg H >qIg  g  g J ;AKg L =aMg N 3AOg P 1!Qg R ;ASg T I!Ug V ;AWg X DQYg Z LQ[g \ A!]g ^ 3A_g ` ;Aag b 9!cg d >qeg f <Qgg h A!ig j =akg  g  g l 9!mg n CAog p DQqg r J1sg t B1ug v B1wg x <Qyg z B1{g | G}g ~ B1g @ MaAg B >qCg F DQGg H <QIg J EaKg L B1Mg N DQOg  g  g P :1Qg R 8Sg T B1Ug V PQRWg X B1Yg Z H[g \ KA]g ^ :1_g ` B1ag b @cg d QRSeg f CAgg h I!ig j Hkg l DQmg n J1og p @qg  g r MNIJKLLMJKJKDEJKOPJKTUUVFGRSMg  g  g i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! 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! c! 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! c! 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! c! 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! c! 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! c! 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! 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! c! 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! c! 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! c! 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! c! 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! c!l MNKLQRCDIJDEJKGHMNHINOGHMNEc! c! c!%v  v Wb bm	Y
 Y
c{>
V $!&"&!..w77!..w77 W{>
h ly -1A 
=.= -= /	=
 I= M= L= L= L= L= -= -= L= I= L=  L!=" -#=$ J%= =& L'=( J)=* ":+=, .z-=. 6z/=0 ,Z1=2 01A3=4 ~5=6 -.B7=8 @AR9=: %l;=< 8==> 8?=@ 9,A=B 7C=D 7E=F 3LG= = =H ,\I=J *<K=L 1,M=N 7O=P 4\Q=R -mS=T /U=V )*>W=X 12EY=Z ./B[=\ *=]=^ 1)_=` (a=b )-c=d :;Le=h %ii=j 0k= =l '0'11;/@/9-7%6y= = =D Di{>
r Ys{>
t  P $"&#' !P 2DP  %P vP !(P  !'!P" "" #$ $#P,  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 !"[  -Pn ,-OoPp 4TqPr GsPt ,uPz !!$'# #{PD "& $$2".&$2'8#0! !EP\ !!'# #]Pd &**.+/*..2/3' '((#T( %d( t	(
 "4( #D( &t( *4( +D( %d( )$( *4( $T( (( )$(  )$!(" -d#($ .t%( ( ePu{>
V%   !!
 '#&! !W%{>
 {>
 { { {	    c                     |                                   d }|                     dd |          \  }}|                     ddd          }d }|dk    r|r|                     |d| j        d                   }|dk    r6|dk    r|                                 }n|d	k    r|                                 }nq|d
k    r6|dk    r|                                 }nP|d	k    r|                                 }n5|dk    r| 	                                }n|dk    r| 
                                }d }d }d }|dk    r<|                     |d          }	|	d }n
|	dk    rdnd}|                     |d          }n|                     |di           }
|                     |
d          }	|	dk    rdnd}|                     |di           }|                     |d          }|                     |          }|                     |d          }||d ||dS )Nr   enableForContractsFr@   subTyper  rB   r   r   rC   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responser  r   r  r   	statusRaw
statusDatapageDatadatetimes                r  fetch_statuszhtx.fetch_status  s^   
!??tU[\\
F"00@TV[\\$7&&vy$,GW:XYYGV##h&&#MMOOHH	))#NNPPHx''h&&#OOQQHH	))#PPRRHz))::<<6!!??AAHD ##((8<<I "+t"3"3-&&x66GG8R@@J(([AAI'611TTFx<<H'',??HnnX..G""8U33C
 
 	
r  c                 n   |                      | j        di           }|                     | j        dd          }|                     |d|          }|                     |d|          }d}|dk    s|dk    r|                     |          }n|                     |          }|                     |dd	          S )
a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :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  r@   typeNrC   rB   datar  )r  r   r   contractPublicGetApiV1TimestampspotPublicGetV1CommonTimestampsafe_integer_2)r  r	  r   r  r  r  s         r  
fetch_timezhtx.fetch_time  s     //$,R@@&&t|]FKK==55H$&..;;FCCHH::6BBH ""8VT:::r  Nmarketreturnc                     |                      |d          }||                     ||          |                     |d          |                     |d          d d dS )NsymbolactualMakerRateactualTakerRate)r  r  r   r   r   r   )r   safe_symbolsafe_number)r  feer  marketIds       r  parse_trading_feezhtx.parse_trading_fee  sl     ##C22&&x88%%c+<==%%c+<==
 
 	
r  r  c                 B   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          S )a  
        fetch the trading fees for a market
        :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>`
        symbolsr0   r  r   )r  r  (spotPrivateGetV2ReferenceTransactFeeRateextendr  r#  )r  r  r	  r  requestr  r  firsts           r  fetch_trading_feezhtx.fetch_trading_fee  s     	V$$vd|
 @@WV\A]A]^^  x44a,,%%eV444r  r%  c                     |                                   || j        }i }t          dt          |                    D ]6}||         }|                     |                     |          |          ||<   7|S )Nr   )r  r%  rangelenfetch_trading_limits_by_id	market_id)r  r%  r	  resultir  s         r  fetch_trading_limitszhtx.fetch_trading_limits  s~     	?lGq#g,,'' 	] 	]AQZF!<<T^^F=S=SU[\\F6NNr  r0   c                     d|i}|                      |                     ||                    }|                     |                     |di                     S )Nr  r  )spotPublicGetV1CommonExchanger'  parse_trading_limitsr  )r  r0   r	  r(  r  s        r  r.  zhtx.fetch_trading_limits_by_id  sW    b
 55dkk'66R6RSS" ((62)N)NOOOr  c                 f    |d|                      |d          |                      |d          didS )Namountzlimit-order-must-greater-thanzlimit-order-must-less-thanminmax)r  limits)r   )r  r;  r  r	  s       r  r5  zhtx.parse_trading_limits#  sP    " ++F4STT++F4PQQ 
 
 	
r  c                 t    |                      |t          | j        |         d         d         | j                  S )N	precisioncost)decimal_to_precisionr*   marketsr   )r  r  r>  s      r  cost_to_precisionzhtx.cost_to_precision=  s2    ((xf9Mk9Z[a9bdhdvwwwr  c                    d}|                      |ddi           \  }}g }g }t          |                                          }t          dt	          |                    D ]}||         }|                     ||          r|dk    r+|                    |                     dd|                     Q|dk    r+|                    |                     dd|                     |dk    rT|                    |                     dd|                     |                    |                     d	d|                     |}t          dt	          |                    D ]}|                     |||                   }|S )
z
        retrieves data on all markets for huobi
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr}   r   r   r@   r   r   rB   rC   )	handle_option_and_paramslistkeysr,  r-  	safe_boolappend"fetch_markets_by_type_and_sub_typearray_concat)r  r	  r   
allMarketspromisesrE  r1  keys           r  fetch_marketszhtx.fetch_markets@  s    55fngWYZZv
EJJLL!!q#d))$$ 		j 		jAq'C~~eS)) j&==OOD$K$KFTXZ`$a$abbbbH__OOD$K$KDRZ\b$c$cddddI%%OOD$K$KFT]_e$f$fgggOOD$K$KHV_ag$h$hiiiq#h--(( 	D 	DA**:x{CCJJr  c                    |dk    }i }d }|s|dk    r/d|d<   |                      |                     ||                    }n|dk    r_|dk    r*|                     |                     ||                    }nY|dk    r)|                     |                     ||                    }n)|                     |                     ||                    }|                     |dg           }t          |          }|d	k     r-t          | j        d
z   | 	                    |          z             g }	t          dt          |                    D ]}
||
         }d }d }d }d }d }d|v }| }d}d}d }d }|r|                     |d          }|                                }|                     |d          }|                     |d          }|d u}| }|d u}| }|rJd}|                    d          }|                     |d          }|                     |d	          }|r|n|}n|rbd}|                     |d          }|rd}|}n|                     |d          }|                    d          }|                     |d	          }|}nGd}|                     |d          }|                     |d          }||z   }|                                }|                     |          }|                     |          }|                     |          }|dz   |z   }d }|rH|r	|d|z   z  }n
|r|d|z   z  }|r1|                     |d          }|d|                     |          z   z  }|                     |d          } |                     |d          }!|                     |d          }"|                     |d          }#|r	|r| }#n|r| }!d }$d }%d }&d }'d }(d })|r|                     |                     |                     |d                              }$|                     |                     |                     |d                              }%|                     |                     |                     |d                              }&|                     d          }'|                     d          }(|                     |d           }*|*d!k    })nq|                     |d"          }$|                     d#          }%|                     d$          }'|                     d%          }(|                     |d&          }+|+d	k    })|                     |d'd#          },|                     |d(d#          }-t+          j        |,d#          pt+          j        |-d#          }.d }/|                     |d)          }0|0z|                     |0          }1|1d         |1d	         z   |1d*         z   |1d+         z   dz   |1d,         z   |1d-         z   dz   |1d.         z   |1d/         z   d0z   }0|                     |0          }/|	                    i d1|d2|d|d3|d4|d5|d6|d7|d8|d9|d|d:|o|.d|d|d;dd<|)d=||||(|'| ||                     |          d d |%|$|&d>|                     d#          |                     |,          |                     |-          d?|#|"d@d d d@|!d d@dA|/|dB           |	S )CNr@   r   allbusiness_typer   rC   rB   r  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_date      r   r         z	 00:00:00r0   lowercaseIdbasequotesettlebaseIdquoteIdsettleIdr  rA   rD   activer   )r7  pricer>  )r9  r:  superMaxr8  )leverager7  rl  r>  )r   r   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper=  r;  createdr  )0contractPublicGetLinearSwapApiV1SwapContractInfor'  *contractPublicGetApiV1ContractContractInfo*contractPublicGetSwapApiV1SwapContractInfospotPublicGetV1CommonSymbols	safe_listr-  r%   r0   jsonr,  r   lowersplitsafe_string_lowersafe_currency_codesafe_integeryymmddr   r  parse_precisionr,   	string_gtstring_to_chars_arrayr  rG  iso8601)2r  r  r  r	  isSpotr(  r  r@  
numMarketsr0  r1  r  rh  ri  rj  r0   rd  r   r@   rB   rC   r   r   rR  rP  partsrU  re  rf  rg  r  rp  ro  minCost	maxAmount	minAmountpricePrecisionamountPrecisioncostPrecisionr   r   rk  rZ  contractStatusleverageRatiosuperLeverageRatiohasLeveragert  createdDatecreatedArrays2                                                     r  rH  z&htx.fetch_markets_by_type_and_sub_typeZ  s   &. 
	W(""+0(PPQUQ\Q\]dflQmQmnnI%%8###NNt{{[bdjOkOkllHHV^^#NNt{{[bdjOkOkllH88Wf9U9UVVHn ..6266\\
>>!$',Z"Z]a]f]fgo]p]p"pqqqq#g,,'' a	 a	AQZFFGHBK'61H<DDFFG )%%fo>> hhjj $ 0 0 I I $ 0 0 I I&d2!z&d2$* +!DHHSMME!33FHEEF"44UA>>G)0=vvgHH 
+#D!33FHEEF +"'#)#//?? $

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

 4##FE22!
 3!
 !
 3!
 !
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r  c                    |                                   |                     |          }i }d}|d         r5|d         |d<   |                     |                     ||                    }n|d         rz|d         r5|d         |d<   |                     |                     ||                    }nq|d         r4|d         |d<   |                     |                     ||                    }n4|d         |d<   |                     |                     ||                    }|                     |d	i           }|                     ||          }| 	                    |d
          }||d<   | 
                    |          |d<   |S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :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   r0   rQ  r   rC   r  rB   tickr  r  r  )r  r  /contractPublicGetLinearSwapExMarketDetailMergedr'  #contractPublicGetMarketDetailMerged)contractPublicGetSwapExMarketDetailMergedspotPublicGetMarketDetailMergedr  r  r  r  )	r  r  r	  r  r(  r  r  r  r  s	            r  fetch_tickerzhtx.fetch_ticker  s    	V$$( 	Z'-d|GO$KKDKKX_agLhLhiiHHI 		Zh h$*4L!CCDKKPWY_D`D`aa h+1$<(II$++V]_eJfJfgg &tGH;;DKKQW<X<XYYHX x44""400%%h55	'{!\\)44zr  c                    |                                   |                     |          }|                     |d          }d}||                     |          }d|v pd|v }d}d}|                     d||          \  }}|                     d||          \  }}i }|dk    }	|dk    }
|dk    }|d	k    }|d
k    }d}|	r|r|r?|
rd|d<   n|rd|d<   nd|d<   |                     |                     ||                    }n|ro|
r*|                     |                     ||                    }n|r*| 	                    |                     ||                    }nWt          | j        dz             t          | j        dz             |                     |                     ||                    }|                     |ddg           }|                     |||          }|                     |d|          S )a_  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://huobiapi.github.io/docs/spot/v1/en/#get-latest-tickers-for-all-pairs
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-a-batch-of-market-data-overview
        :see: https://huobiapi.github.io/docs/dm/v1/en/#get-a-batch-of-market-data-overview
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-a-batch-of-market-data-overview-v2
        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   Nr  rP  r   r@   rC   rB   r   r   r  rO  za fetchTickers() you have to set params["type"] to either "swap" or "future" for inverse contractsz_ fetchTickers() you have to set params["subType"] to either "linear" or "inverse" for contractsr  ticksr  )r  market_symbolsr   r  r  handle_sub_type_and_params4contractPublicGetLinearSwapExMarketDetailBatchMergedr'  (contractPublicGetMarketDetailBatchMerged.contractPublicGetSwapExMarketDetailBatchMergedr$   r0   spotPublicGetMarketTickerssafe_list_2parse_tickersfilter_by_array_tickers)r  r%  r	  r)  r  isSubTypeRequestedr  r  r(  r  rC   rB   r   r   r  
rawTickerstickerss                    r  fetch_tickerszhtx.fetch_tickers3  s    	%%g..  !,,[[''F'61Q&7P99.&RXYYf99.&RXYY&.("X%i' 	U+ 	U P 5/8GO,, 5/5GO,,/4GO,TTUYU`U`ahjpUqUqrr P V#LLT[[Y`bhMiMijjHH V#RRSWS^S^_fhnSoSoppHH&tw  2U  (U  V  V  V"47  .O  $O  P  P  P66t{{7F7S7STTHf %%hDD
$$Z&AA++GXwGGGr  c                    |                                   |                     |          }|                     |          }d}d}|                     d||          \  }}|                     d||          \  }}d}|dk    s|dk    r|dk    r|                     |          }na|dk    r|dk    r|                     |          }n?|dk    r|dk    r|                     |          }nt          | j	        dz   |z   dz             | 
                    |d	i           }|                     |d
g           }|                     ||          S )a  
        fetches the last price for multiple markets
        :see: https://www.htx.com/en-us/opend/newApiPages/?id=8cb81024-77b5-11ed-9966-0242ac110003 linear swap & linear future
        :see: https://www.htx.com/en-us/opend/newApiPages/?id=28c2e8fc-77ae-11ed-9966-0242ac110003 inverse future
        :see: 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
        Nru   rB   rC   r   r   z$ fetchLastPrices() does not support z markets yetr  r  )r  r  get_market_from_symbolsr  r  (contractPublicGetLinearSwapExMarketTrade"contractPublicGetSwapExMarketTradecontractPublicGetMarketTrader$   r0   r  ry  parse_last_prices)	r  r%  r	  r  r  r  r  r  r  s	            r  fetch_last_priceszhtx.fetch_last_prices  sq    	%%g..--g6699:KVU[\\99:KVU[\\fV^^!1!1H9L9LDDVLLHH4 fnn7i#7#7>>vFFHH. hW	%9%988@@HH0 tw)OORVVYgghhhx44~~dFB//%%dG444r  c                     |                      |dd          }|                     ||          }|                     |d          }|                     |d          }|d         d d |||dS )Nr  rQ  rl  	direction)r  r  r  rl  sider  )r  safe_marketr   r   )r  entryr  r"  rl  r  s         r  parse_last_pricezhtx.parse_last_price  s    %%eXGG!!(F33  00$$UK88	 X&
 
 	
r  r  c                 p   |                                   |                     |          }ddi}d}|d         r5|d         |d<   |                     |                     ||                    }n|d         rz|d         r5|d         |d	<   |                     |                     ||                    }n|d
         r4|d         |d<   |                     |                     ||                    }np|:|dk    r)|dk    r#|dk    r|dk    rt          | j        dz             |dk    r||d<   |d         |d	<   |                     |                     ||                    }d|v r|d         s-t          | j        dz   | 
                    |          z             |                     |d          }|                     |d|                     |d                    }|                     |||          }	|                     |d          |	d<   |	S t          | j        dz   | 
                    |          z             )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r  step0Nr   r0   rQ  r   rC   r  rB   r   r         zP fetchOrderBook() limit argument must be None, 5, 10, 20, or 150, default is 150depthr  z+ fetchOrderBook() returned empty response: r  r:   noncez2 fetchOrderBook() returned unrecognized response: )r  r  (contractPublicGetLinearSwapExMarketDepthr'  contractPublicGetMarketDepth"contractPublicGetSwapExMarketDepthr   r0   spotPublicGetMarketDepthr    rz  r  r  parse_order_bookr   )
r  r  r  r	  r  r(  r  r  r  r0  s
             r  fetch_order_bookzhtx.fetch_order_book	  s{    	V$$ G

 ( 	S'-d|GO$DDT[[QXZ`EaEabbHHI 	Sh a$*4L!<<T[[RX=Y=YZZ a+1$<(BB4;;wX^C_C_`` QJJUb[[u{{RU$TW  0B  &B  C  C  C C<<',GG$ &tGH44T[[&5Q5QRRH6 XF# o*W WZ^ZcZcdlZmZm mnnn??8V44D))$d6G6GRV6W6WXXI**4CCF"//i@@F7OMDG&ZZ]a]f]fgo]p]ppqqqr  c                    |                      |dd          }|                     ||          }|d         }|                     |dd          }|                     |dd|          }|                      |dd          }|                     |d	          }|                     |d
          }|%|                    d          }	|	d         }|	d         }|                     |d          }
|                      |dd          }|                      |dd          }|                     |d|          }|                     |d          }d }|                     |d          }|(t          j        |                     |d                    }|                      |dd          }|                     |          }|                     |d          }|F|t          j	        |d          r/|                     |d          }||}|                     |          }|||d}| 
                    |g d          }|                     |||||                     |          ||||
||||d|          S )NrQ  r  r  
created-at
created_atr_  order-idorder_idr  r  rS  r   r   rolerl  trade_pricefilled-amountr7  trade_volumetrade_turnoverfilled-fees	trade_feezfee-currency	fee_assetzfilled-points0zfee-deduct-currencyr>  currency)trade_idztrade-idr0   )r0   r  orderr  r  r  r  r  takerOrMakerrl  r7  r>  r!  )r  r  r  r   r|  r}  r,   
string_negr~  string_equalssafe_string_n
safe_trader  )r  trader  r"  r  r  r  r  r  	typePartsr  priceStringamountString
costStringr!  feeCostfeeCurrencyIdfeeCurrencyfilledPointsfeeDeductCurrencyr0   s                        r  parse_tradezhtx.parse_trade^	  s   ^ %%e_hGG!!(F33!''t\BB	''|]IVV	""5*jAA{33v..

3IQ<DQ<D--eV<<((GG))%(KK''~|LL%%e-=>>
""5-88?()9)9%)M)MNNG**5.+NN--m<<''??#G$9'3$G$G$($4$4U<Q$R$R!$0*G"&"9"9:K"L"LK' C 'E'E'EFF"Y//( " 
  
   	r  sincec                     d}||                      |          }d}|                     d||          \  }}|dk    rt          | j        dz             |                     |||||          S )a  
        fetch all the trades made from a single 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   r@   z6 fetchOrderTrades() is only supported for spot markets)r  r  r$   r0   fetch_spot_order_trades)r  r0   r  r  r  r	  r  r
  s           r  fetch_order_tradeszhtx.fetch_order_trades	  s     [[((F
!??@RTZ\bcc
Ftw)aabbb++BufMMMr  c                     |                                   d|i}|                     |                     ||                    }|                     |d         d ||          S )Nr  r  )r  .spotPrivateGetV1OrderOrdersOrderIdMatchresultsr'  parse_trades)r  r0   r  r  r  r	  r(  r  s           r  r  zhtx.fetch_spot_order_trades	  sd    
 FFt{{SZ\bGcGcdd  &!14FFFr  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S d}||                     |          }d}|                     d||          \  }}i }d}	|dk    ru| |                     |          }|d         |d<   |||d<   |||d	<   |                     d
||          \  }}|                     |                     ||                    }	nj|t          | j	        dz             |d         |d<   d|d<   |||d<   |                     d||          \  }}|||d<   |d         rd}
| 
                    d|          \  }
}|
dn|
}
|
dk    r*|                     |                     ||                    }	n|
dk    r)|                     |                     ||                    }	n|d         r|dk    r5|d         |d<   |                     |                     ||                    }	nM|dk    r*|                     |                     ||                    }	nt          | j	        dz   |z   dz             |                     |	d          }t#          |t$                    s|                     |d          }|                     ||||          S )a5  
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-get-history-match-results-via-multiple-fields-new
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-get-history-match-results-via-multiple-fields-new
        :see: 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   paginateNr@   r0   r  size
start-timeend-timez+ fetchMyTrades() requires a symbol argumentr   r   
trade_type
start_timeend_time	page_sizer   crossisolatedr   rC   rj  rB   z" fetchMyTrades() does not support  marketsr  trades)r  rC  fetch_paginated_call_dynamicr  r  handle_until_option!spotPrivateGetV1OrderMatchresultsr'  r   r0   handle_margin_mode_and_params7contractPrivatePostLinearSwapApiV3SwapMatchresultsExact<contractPrivatePostLinearSwapApiV3SwapCrossMatchresultsExact1contractPrivatePostApiV3ContractMatchresultsExact1contractPrivatePostSwapApiV3SwapMatchresultsExactr$   r  r  rD  r  )r  r  r  r  r	  r  r  r
  r(  r  
marginModer'  s               r  fetch_my_tradeszhtx.fetch_my_trades	  sC    	88R\]]& 	d44_feUZ\bccc[[((F
!??QWY_``
F
& !V,,$*4L! "' (-%"66z7FSSOGV==dkk'SY>Z>Z[[HH~'2_(_```"(,GJ$%GL! (-%"66z7FSSOGV ',$h q!
%)%G%GY_%`%`"
F)3);WW*
++#[[\`\g\ghoqw\x\xyyHH7**#``aealalmtv|a}a}~~H	" q))(.z(:GH%#UUVZVaVabikqVrVrssHH6))#UUVZVaVabikqVrVrssHH&tw1U'UXb'beo'opppF 622&$'' 	7__VX66F  >>>r    c                    |                                   |                     |          }i }|t          |d          |d<   d}|d         rz|d         r5|d         |d<   |                     |                     ||                    }n|d         r4|d         |d	<   |                     |                     ||                    }n|d
         ro|d         |d	<   |d         r*|                     |                     ||                    }nf|d         r)|                     |                     ||                    }n4|d         |d<   |                     |                     ||                    }|                     |dg           }g }	t          dt          |                    D ]p}
|                     ||
         dg           }t          dt          |                    D ]3}|                     ||         |          }|	                    |           4q|                     |	d          }	|                     |	|d         ||          S )a  
        :see: https://huobiapi.github.io/docs/spot/v1/en/#get-the-most-recent-trades
        :see: https://huobiapi.github.io/docs/dm/v1/en/#query-a-batch-of-trade-records-of-a-contract
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-a-batch-of-trade-records-of-a-contract
        :see: 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>`
        N  r  rC   r   r0   r  r   rQ  rB   r  r   r  )r  r  r9  #contractPublicGetMarketHistoryTrader'  /contractPublicGetLinearSwapExMarketHistoryTrade)contractPublicGetSwapExMarketHistoryTradespotPublicGetMarketHistoryTrader  r,  r-  r  rG  sort_byfilter_by_symbol_since_limit)r  r  r  r  r	  r  r(  r  r  r0  r1  r'  jr	  s                 r  fetch_tradeszhtx.fetch_trades
  sn    	V$$
 !%..GFO( 	Zi  n$*4L!CCDKKPWY_D`D`aa! n+1$<(OOPTP[P[\cekPlPlmmF^ 	Z'-d|GO$i  nII$++V]_eJfJfgg! nOOPTP[P[\cekPlPlmm &tGH;;DKKQW<X<XYYH2 x44q#d))$$ 	% 	%A__T!Wfb99F1c&kk** % %((F;;e$$$$% fk22009I5RWXXXr  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr0   r  r  r  r  r7  )safe_timestampr   )r  ohlcvr  s      r  parse_ohlcvzhtx.parse_ohlcv
  s     t,,UF++UF++UE**UG,,UH--
 	
r  r   c           	         |                                   d}|                     |dd          \  }}|r|                     d|||||d          S |                     |          }d|                     | j        ||          i}|                     |ddg          }	|                     |ddg          }d}
|                     |d	          \  }
}|
| 	                    |
dz            nd}|d
         r|t          |d          |d<   nd}|	|                     |          }d}|%|                                 }|||dz
  z  z
  |d<   |}n9| 	                    |dz            }||d<   |                     |||dz
  z            }||n||d<   d}|d         r|d         r|d         |d<   |	dk    r+|                     |                     ||                    }n|	dk    r+|                     |                     ||                    }n|	dk    r)t#          | j        dz   |d         z   dz   |	z   dz             |                     |                     ||                    }n4|d         r|d         |d<   |	dk    r+|                     |                     ||                    }n|	dk    r)t#          | j        dz   |d         z   dz   |	z   dz             |	dk    r+|                     |                     ||                    }n|                     |                     ||                    }ne|d         r|d         |d<   |d         r|	dk    r+|                     |                     ||                    }n|	dk    r)t#          | j        dz   |d         z   dz   |	z   dz             |	dk    r+|                     |                     ||                    }n|                     |                     ||                    }n|d         r|	dk    r+|                     |                     ||                    }nT|	dk    r)t#          | j        dz   |d         z   dz   |	z   dz             |	dk    r*|                     |                     ||                    }n|                     |                     ||                    }n|d         |d<   d}|                     |ddd          \  }}|s?|t          |d          |d<   |                     |                     ||                    }nb|| 	                    |dz            |d<   |||d<   |t          d|          |d<   |                     |                     ||                    }|                     |d g           }|                     |||||          S )!a#  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://huobiapi.github.io/docs/spot/v1/en/#get-klines-candles
        :see: https://huobiapi.github.io/docs/dm/v1/en/#get-kline-data
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-kline-data
        :see: 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   r  r2  period	priceTyperl  Nuntilr   r4  r  r   fromtorC   r   r0   r  markindexpremiumIndex r  z has no api endpoint for z kline datar   rQ  rB   r   Tr  )r  rC  "fetch_paginated_call_deterministicr  r   r   r  omithandle_param_integerparse_to_intr9  parse_timeframesecondssum1contractPublicGetIndexMarketHistoryMarkPriceKliner'  (contractPublicGetIndexMarketHistoryIndexr   r0   #contractPublicGetMarketHistoryKline;contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline>contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline/contractPublicGetLinearSwapExMarketHistoryKline5contractPublicGetIndexMarketHistorySwapMarkPriceKline8contractPublicGetIndexMarketHistorySwapPremiumIndexKline)contractPublicGetSwapExMarketHistoryKlinespotPublicGetMarketHistoryKline!spotPublicGetMarketHistoryCandlesry  parse_ohlcvs)r  r  	timeframer  r  r	  r  r  r(  rC  rD  untilSecondsdurationcalcualtedEndnowstartr  useHistoricalr  s                      r  fetch_ohlcvzhtx.fetch_ohlcv
  s     	88zZZ& 	x::<QVX]_hjprvwwwV$$d&&t	9MM
 &&vW/EFF	6K#9::11&'BBv;@;Lt((666SW* 	^ "%eT"2"2  //	:: $=,,..C&)H	,B&BGFO$'MM --edl;;E&+GFO$(HHUH	4J$K$KM1=1IP]( 9	`i  r$*4L!&&#UUVZVaVabikqVrVrssHH'))#LLT[[Y`bhMiMijjHH.00$TWs]VF^%CFa%adm%mp}%}~~~#GGT[]cHdHdeeHH! 	r+1$<(&&#__`d`k`klsu{`|`|}}HH'))$TWs]VF^%CFa%adm%mp}%}~~~.00#bbcgcncnovx~cc   A   AHH#SSTXT_T_`gioTpTpqqHF^ $	`'-d|GO$i  r&&#YYZ^ZeZefmouZvZvwwHH'))$TWs]VF^%CFa%adm%mp}%}~~~.00#\\]a]h]hiprx]y]yzzHH#MMdkkZaciNjNjkkHH! r&&#__`d`k`klsu{`|`|}}HH'))$TWs]VF^%CFa%adm%mp}%}~~~.00#bbcgcncnovx~cc   A   AHH#SSTXT_T_`gioTpTpqqH &tGH M$($A$A&,Xvx|$}$}!M6  `$&)%&6&6GFO??GU[@\@\]] $&*&7&7&E&EGFO+$0GDM$&)$&6&6GFOAA$++gW]B^B^__ ~~h33  vy%GGGr  c                     |                                   |                     |          }|                     |d          }|                     |          S )a  
        fetch all the accounts associated with a profile
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        r  )r  spotPrivateGetV1AccountAccountsr  parse_accounts)r  r	  r  r  s       r  fetch_accountszhtx.fetch_accountsr  sR     	77?? x00""4(((r  c                     |                      |d          }|                     | j        di           }|                     |||          }||                      |d          |d dS )Nr  r  r0   )r  r0   r  code)r   r  r   )r  accounttypeIdr  r  s        r  parse_accountzhtx.parse_account  sp     !!'622t|^RHH|VV<<""7D11	
 
 	
r  c                 v   |                                  }|                     |dd          }||S |dk    r|dk    rd}n|dk    rd}|d n|                     |          }t          dt	          |                    D ]}||         }	|                     |	d	          }
|                     |
d
d           }|                     |	d          }|dk    r||k    r|                     |	d          c S r||k    r|                     |	d          c S |                     |di           }|                     |d          S )N	accountId
account-idr@   r$  r  r%  rA   r   r  subtyper  r0   )load_accountssafe_value_2r/  r,  r-  r  r   )r  r  r0  r  r	  accountsrp  r"  r1  rl  r  rr  typeFromAccountdefaultAccounts                 r  fetch_account_id_by_typezhtx.fetch_account_id_by_type  so   %%''%%fk<HH	 6>>W$$%z))"N441G1Gq#h--(( 		7 		7AqkG??7F33D&&tY==G"..w??Oxh&&++GT::::: '((''66666 )1b99555r  c                 J   |                      |          }|                     |dg           }i }i | j        d<   i | j        d<   t          dt	          |                    D ]A}||         }|                     |d          }|                     |          }i | j        d         |<   |                     |dg           }	i }
|                     |d          }|dk    }d	}d	}d	}d
}d
}t          dt	          |	                    D ]l}|	|         }|                     |d          }|                     |dd          }|| j        d         |         |<   || j        d         |<   |                     |          }| 	                    |d          }| 	                    |d          }|                     |d          }|                     |d          }|dk    }|dk    }|r|n|}|r|n|}|o|}| 
                    |                     |d                    }|||nt          j        ||          }| 	                    |d          }|||d	d	d||dd|||||                     |          d	|
|<   n||||||d	d	d	d	d||dd	d	dd|                     |          |
d||<   C|S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  networkChainIdsByNamesnetworkNamesByChainIdsr   r  chains
instStatusnormalNFchain	baseChaindisplayNameminWithdrawAmtmaxWithdrawAmtwithdrawStatusdepositStatusallowedwithdrawPrecisiontransactFeeWithdrawr8  )depositr   )	r  r0   networkr;  rk  r  r   r!  r=  )r7  r   r  )r  rk  r0   rk  r  r   r!  r1   r;  r=  r
  )"spotPublicGetV2ReferenceCurrenciesr  r   r,  r-  r   r~  r  network_id_to_coder   r  r,   
string_minr  )r  r	  r  r  r0  r1  r  
currencyIdrk  r|  r
  r}  currencyActiveminPrecisionminWithdrawmaxWithdrawr  r   r;  
chainEntryuniqueChainIdtitlenetworkCoder  r  withdrawEnableddepositEnabledrk  r=  r!  s                                 r  fetch_currencieszhtx.fetch_currencies  su    ::6BBL x4413-.13-.q#d))$$ O	 O	AGE))%<<J**:66D;=DL1248__UHb99FH))%>>J'83NLKKGH1c&kk** ' '#AY
 $ 0 0W E E**:{MRRFS56t<UCHM56}E"55mDD"..z;KLL"..z;KLL!%!1!1*>N!O!O $ 0 0_ M M#1Y#>"/9"</>M??X-;I..'(;^ 001A1A*Na1b1bcc	(1=1E99GL^_hjvLwLwL&&z3HII&'* $(#'$ $
 $/#.% %	 	 %- /!%!2!29!=!=%) )%%*  ("$  $# 
  +*! !
  $#     "..|<<$1 F4LL4 r  c                 H   t          | j        d                                                   }t          |          }|dk    rt	          | j        dz             |                     | j        d         ||          }t          t          |           	                    |          S )Nr{  r   z7 networkIdToCode() - markets need to be loaded at first)
rD  r   rE  r-  r   r0   r  r  r.   r  )r  	networkIdcurrencyCoderE  
keysLengthnetworkTitler  s         r  r  zhtx.network_id_to_code3  s    DL!9:??AABBYY
??*c cdddt|4L'MyZcddS$22<@@@r  c                    |t          | j        dz             t          | j        d                                                   }t          |          }|dk    rt          | j        dz             |                     | j        d         |i           }||v r||         S t          t          |           
                    |          }|                     |||          S )Nz3 networkCodeToId() requires a currencyCode argumentrz  r   z7 networkCodeToId() - markets need to be loaded at first)r   r0   rD  r   rE  r-  r   r  r  r.   network_code_to_id)r  r  r  rE  r  uniqueNetworkIdsr  r  s          r  r  zhtx.network_code_to_id<  s    #DG.c$cdddDL!9:??AABBYY
??*c cddd??4<8P+QS_acdd***#K00 d++>>{KKL??#3\<PPPr  c                 r   |                                   d}|                     dd|          \  }}|                     | j        di           }|                     |ddd          }|                     |ddg          }i }|dk    }|dk    }|                     | j        dd	d
          }|                     |dd	|          }	|                     |dd	|	          }	|	dk    }
|	d
k    }d}|                     d|          \  }}|                     |dd	g          }|dk    }|dk    }|dk    p|o|p|}d}|s|r|rX|r+|                     | 	                    ||                    }na| 
                    | 	                    ||                    }n6|                                  |                     |dd|          }||d<   |                     | 	                    ||                    }n|r*|                     | 	                    ||                    }n|rV|r*|                     | 	                    ||                    }n|                     | 	                    ||                    }nW|
rU|r*|                     | 	                    ||                    }n)|                     | 	                    ||                    }d|i}|                     |d          }|s|r|rt'          dt)          |                    D ]}||         }|                     |                     |d                    }|                     |d          }i }t'          dt)          |                    D ]O}||         }|                     |d          }|                     |          }|                     |||          ||<   P|                     |          ||<   ѐna|                     |dg           }t'          dt)          |                    D ]O}||         }|                     |d          }|                     |          }|                     |||          ||<   P|                     |          }n|rWt'          dt)          |                    D ]6}||         }|                     |d          }|                     |          }|r|                     |di           }t'          dt)          |                    D ]h}||         }|                     |d          } ||                     |d          d}!|                     |           }|!||<   |                     |          }i|                                 }"|                     |d          |"d<   |                     |d          |"d<   |"||<   |                     |          }8nl|r|                     |di           }#|rt'          dt)          |                    D ]}||         }|                     |dd          } |                     |           }$|                     |d          }|                     |          }%|                     |$d |%d!                   }|m|                                 }"|                     |d"          |"d<   |                     |d          |"d<   i }&|"|&|<   |$d         }|                     |&          ||<   nB|                                 }"|                     |#d#          |"d<   |                     |#d"          |"d$<   |                     |#dd          }|                     |          }|"||<   |                     |          }n|
rt'          dt)          |                    D ]}||         }|                     |d          }|                     |          }|                                 }"|                     |d          |"d<   |                     |d          |"d<   |"||<   |                     |          }|S )%aY  
        :see: https://huobiapi.github.io/docs/spot/v1/en/#get-account-balance-of-a-specific-account
        :see: https://www.htx.com/en-us/opend/newApiPages/?id=7ec4b429-7773-11ed-9966-0242ac110003
        :see: https://www.htx.com/en-us/opend/newApiPages/?id=10000074-77b7-11ed-9966-0242ac110003
        :see: https://huobiapi.github.io/docs/dm/v1/en/#query-asset-valuation
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-user-s-account-information
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-query-user-s-account-information
        :see: 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>`
        NrZ   isUnifiedAccountunifiedFr@   rC   r  r  r   r   r%  r$  rA   rq  r  r  r   r  rD  r  margin_assetisolated_swaprQ  margin_available)rk  freemargin_staticr  margin_frozenusedmargin_accountrg  rk  margin_balancewithdraw_availabletotal)r  r  r  r   rt  rL  r  r+  %spotPrivateGetV1MarginAccountsBalancer'  *spotPrivateGetV1CrossMarginAccountsBalancers  rx  /spotPrivateGetV1AccountAccountsAccountIdBalance3contractPrivateGetLinearSwapApiV3UnifiedAccountInfo1contractPrivatePostLinearSwapApiV1SwapAccountInfo6contractPrivatePostLinearSwapApiV1SwapCrossAccountInfo+contractPrivatePostApiV1ContractAccountInfo+contractPrivatePostSwapApiV1SwapAccountInfor,  r-  r  r   r~  parse_margin_balance_helpersafe_balancer   rl  r  safe_currency)'r  r	  r  r   r  r(  r@   rC   r  r  r   r   r0  r%  r$  rA   r  rp  r0  r  r1  r  r  balances	subResultr;  balancer  rk  marginAssetr  r  r"  
subBalancerl  r)  r  r  accountsByCodes'                                          r  fetch_balancezhtx.fetch_balanceJ  s    	99.$PVWWf//$,CC,,V5GTYZZ6$6	#BCC("++DL:JIW_``$$W.>	>ZZ$$V-=y'RRi'X%
!??PVWW
F6$4i#@AA*,w&("E(D%2C8 	j6 	j 	n m#II$++V]_eJfJfggHH#NNt{{[bdjOkOkllHH""$$$ 99$dFSS	(1%OOPTP[P[\cekPlPlmm 	jOOPTP[P[\cekPlPlmmHH 		j uQQRVR]R]^egmRnRnooVVW[WbWbcjlrWsWstt 	j jKKDKKX_agLhLhiiKKDKKX_agLhLhii@ (#x00 R	/6 R	/ 3q#d)),, 
B 
BA GE!--d.>.>uh.O.OPPF#uf==H "I"1c(mm44 e e"*1+%)%5%5gz%J%J
#66zBB*.*J*J7TXZc*d*d	$%)%6%6y%A%AF6NN
B  ??4<<q#h--00 [ [A&qkG!%!1!1':!F!FJ22:>>D#'#C#CGTSY#Z#ZF4LL**622 =	/1c$ii(( 7 7Q"..unEE#66{CC 7$(OOE?B$O$OM"1c-&8&899 	; 	;"/"2#'#3#3G_#M#M$0$($4$4W>P$Q$Q& &
 "&!1!1(!;!;)3v!%!2!26!:!:	; #llnnG&*&6&6uo&N&NGFO&*&6&6uo&N&NGFO+2F<(!..v66FF+7,  &	/OOD!R00E 3q#d)),, K KA"1gG#11'?L\]]H!--h77F!%!1!1'>!J!JJ#11*==H++FHhv>NOOD '"&,,..*.*:*:7DT*U*U*.*:*:7O*T*T)+/6t,!'!1)-):):>)J)Jv#K& ,,.."&"2"25:N"O"O#'#3#3E;K#L#L !//~xPP
..z::&t**622 		/1c$ii(( ' 'q'!--gx@@
..z::,,.."&"2"27<N"O"O"&"2"27O"L"L&t&&v..Fr  c                 ,   |                                   d}||                     |          }d}|                     d||          \  }}i }d}|dk    rs|                     |d          }|+|                     |                     ||                    }n||d<   |                     |                     ||                    }ny|t          | j        dz             | 	                    |dd          }|||d<   n||d<   | 
                    |ddg          }|d	         |d
<   |d         rd}	|                     d|          \  }	}|	dn|	}	|	dk    r*|                     |                     ||                    }n|	dk    r)|                     |                     ||                    }n|d         r|dk    r5|d         |d<   |                     |                     ||                    }nM|dk    r*|                     |                     ||                    }nt!          | j        dz   |z   dz             |                     |d          }
t%          |
t&                    r|                     |
d          }
|                     |
          S )a?  
        fetches information on an order made by the user
        :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   r@   clientOrderIdr  z( fetchOrder() requires a symbol argumentclient_order_idr  r0   rQ  r   r$  r%  r   rC   rj  r  rB   z fetchOrder() does not support r&  r  r   )r  r  r  r   )spotPrivateGetV1OrderOrdersGetClientOrderr'  "spotPrivateGetV1OrderOrdersOrderIdr   r0   r  rL  r+  /contractPrivatePostLinearSwapApiV1SwapOrderInfo4contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo)contractPrivatePostApiV1ContractOrderInfo)contractPrivatePostSwapApiV1SwapOrderInfor$   r  r  rD  parse_order)r  r0   r  r	  r  r
  r(  r  r  r0  r  s              r  fetch_orderzhtx.fetch_orderz  s    	[[((F
!??fV\]]
F
  ,,V_EEM(  II$++V]_eJfJfgg&(
#BB4;;wX^C_C_``~'2\(\]]] ..v7H/ZZM$&(
##-:)*6,=+OPP'-d|GO$h n!
%)%G%GV\%]%]"
F)3);WW*
++#SSTXT_T_`gioTpTpqqHH7**#XXY]YdYdelntYuYuvvH	" n))(.z(:GH%#MMdkkZaciNjNjkkHH6))#MMdkkZaciNjNjkkHH&tw1R'RU_'_bl'lmmm| &11eT"" 	.OOE1--E&&&r  c                     d }||v r	||         }n|                                  }|d         dk    r|                     |d          |d<   |d         dk    r|                     |d          |d<   |S )Nr  r	  r  r  frozenr  )rl  r   )r  r  rk  r0  rl  s        r  r  zhtx.parse_margin_balance_helper;  s}    6>>TlGGllnnG6?g%%"..w	BBGFO6?h&&"..w	BBGFOr  c                    |                      | j        dd          }|dk    r|t          | j        dz             |                                  d }d|i}| |                     |          }|d         |d<   |||d<   |                     |d          |d	<   |                     d	||          \  }}|||d
<   d }	|dk    r*|                     | 	                    ||                    }	n)| 
                    | 	                    ||                    }	|                     |	dg           }
|                     |
|||          S )Nr  r  z) fetchOrders() requires a symbol argumentstatesr0   r  r  i L
r  r  r  )r   r   r   r0   r  r  rQ  r)  spotPrivateGetV1OrderOrdersr'  spotPrivateGetV1OrderHistoryry  parse_orders)r  r  r  r  r  r	  methodr  r(  r  r  s              r  fetch_spot_orders_by_stateszhtx.fetch_spot_orders_by_statesG  si   !!$,0KMopp777~'2](]^^^ f
" [[((F &tGH$)GL!"&((52E"F"FGJ22:wOO#GFO77777GV8T8TUUHH88Wf9U9UVVH6 ~~h33  vue<<<r  c                 4    |                      d||||          S )NzGpre-submitted,submitted,partial-filled,filled,partial-canceled,canceledr  r  r  r  r  r	  s        r  fetch_spot_orderszhtx.fetch_spot_orders  s<    //0y  |B  DI  KP  RX  Y  Y  	Yr  c                 4    |                      d||||          S )Nz filled,partial-canceled,canceledr  r  s        r  fetch_closed_spot_orderszhtx.fetch_closed_spot_orders  s#    //0RTZ\achjpqqqr  c                    |t          | j        dz             |                                  |                     |          }ddd}d }|                     |d          }|                     |d          }	|                     |dd          }
|                     |g d	          }|s|	s|
r|||d
<   |d         |d<   d|d<   n|||d<   |d         |d<   d|d<   |                     d||          \  }}|d         rd }|                     d|          \  }}|dn|}|dk    r|r+| 	                    | 
                    ||                    }n|	r+|                     | 
                    ||                    }n|
r+|                     | 
                    ||                    }nd|                     | 
                    ||                    }n9|dk    r|r+|                     | 
                    ||                    }n|	r+|                     | 
                    ||                    }n|
r+|                     | 
                    ||                    }n|                     | 
                    ||                    }n|d         rx|d         r|r+|                     | 
                    ||                    }nC|	r+|                     | 
                    ||                    }n|
r*|                     | 
                    ||                    }n|                     | 
                    ||                    }n|d         r|d         |d<   |r*|                     | 
                    ||                    }n|	r*|                     | 
                    ||                    }nU|
r*|                     | 
                    ||                    }n)|                     | 
                    ||                    }|                     |d          }t5          |t6                    s|                     |dg           }|                     ||||          S )Nz1 fetchContractOrders() requires a symbol argumentr   r  )r   r   stopstopLossTakeProfittrailingFr  r  r  r#  r0   rQ  Z   r_  r!  r   r   r  r"  r   fetchContractOrdersr$  r%  r   rB   rC   rj  r  r  orders)r   r0   r  r  r  rF  rL  r)  r+  6contractPrivatePostLinearSwapApiV1SwapTriggerHisordersr'  3contractPrivatePostLinearSwapApiV1SwapTpslHisorders4contractPrivatePostLinearSwapApiV1SwapTrackHisorders/contractPrivatePostLinearSwapApiV3SwapHisorders;contractPrivatePostLinearSwapApiV1SwapCrossTriggerHisorders8contractPrivatePostLinearSwapApiV1SwapCrossTpslHisorders9contractPrivatePostLinearSwapApiV1SwapCrossTrackHisorders4contractPrivatePostLinearSwapApiV3SwapCrossHisorders0contractPrivatePostSwapApiV1SwapTriggerHisorders-contractPrivatePostSwapApiV1SwapTpslHisorders.contractPrivatePostSwapApiV1SwapTrackHisorders)contractPrivatePostSwapApiV3SwapHisorders0contractPrivatePostApiV1ContractTriggerHisorders-contractPrivatePostApiV1ContractTpslHisorders.contractPrivatePostApiV1ContractTrackHisorders)contractPrivatePostApiV3ContractHisordersr  rD  r  )r  r  r  r  r	  r  r(  r  r  r  r  r0  r  s                r  fetch_contract_orderszhtx.fetch_contract_orders  s   >#DG.a$abbbV$$ 	
 	
 vv..!__V5IJJ>>&*e<<6#M#M#MNN 
	 % 
	  
	  ',$'-d|GO$%'GM"" (-%"(,GJGFO22:wOO( )	lJ!%!C!CDY[a!b!bJ%/%7jJZ'' r#ZZ[_[f[fgnpv[w[wxxHH' r#WWX\XcXcdkmsXtXtuuHH r#XXY]YdYdelntYuYuvvHH#SSTXT_T_`gioTpTpqqHHw&& w#__`d`k`klsu{`|`|}}HH' w#\\]a]h]hiprx]y]yzzHH w#]]^b^i^ijqsy^z^z{{HH#XXY]YdYdelntYuYuvvHI 	lf~ l l#TTUYU`U`ahjpUqUqrrHH' l#QQRVR]R]^egmRnRnooHH l#RRSWS^S^_fhnSoSoppHH#MMdkkZaciNjNjkkHH! 	l$*:$6! l#TTUYU`U`ahjpUqUqrrHH' l#QQRVR]R]^egmRnRnooHH l#RRSWS^S^_fhnSoSoppHH#MMdkkZaciNjNjkkH^ 622&$'' 	;__VXr::F  >>>r  c           	      b    ddi}|                      ||||                     ||                    S )Nr   z5,6,7)r  r'  )r  r  r  r  r	  r(  s         r  fetch_closed_contract_ordersz htx.fetch_closed_contract_ordersm  s9    g
 ))&%GU[@\@\]]]r  c                 R   |                                   d}||                     |          }d}|                     d||          \  }}|dk    p|dk    }|r|t          | j        dz   |z   dz             |r|                     ||||          S |                     ||||          S )a  
        :see: https://huobiapi.github.io/docs/spot/v1/en/#search-past-orders
        :see: https://huobiapi.github.io/docs/spot/v1/en/#search-historical-orders-within-48-hours
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-get-history-orders-new
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-get-history-orders-new
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-history-orders-new
        :see: 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.stop]: *contract only* if the orders are stop 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   rB   rC   z. fetchOrders() requires a symbol argument for  orders)r  r  r  r   r0   r  r  )r  r  r  r  r	  r  r
  r   s           r  fetch_orderszhtx.fetch_orderss  s    & 	[[((F
!??vW]^^
F&(EjH.D 	y#DG.^$^ak$knw$wxxx 	H--feUFKKK))&%GGGr  c                 p   |                                   d}|                     |dd          \  }}|r|                     d||||d          S d}||                     |          }d}|                     d||          \  }}|dk    r|                     ||||          S |                     ||||          S )as  
        :see: https://huobiapi.github.io/docs/spot/v1/en/#search-past-orders
        :see: https://huobiapi.github.io/docs/spot/v1/en/#search-historical-orders-within-48-hours
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-get-history-orders-new
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-get-history-orders-new
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-history-orders-new
        :see: 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>`
        Fra   r  r6   Nr@   )r  rC  r(  r  r  r  r  )r  r  r  r  r	  r  r  r
  s           r  fetch_closed_orderszhtx.fetch_closed_orders  s    " 	88ATV`aa& 	m445H&RWY^`fhklll[[((F
!??@SU[]cdd
F00vNNN44VUE6RRRr  c                 Z
   |                                   d}||                     |          }i }d}|                     d||          \  }}d}|dk    r||d         |d<   |                     |d          }	|	l|                                  t          dt          | j                            D ]5}
| j        |
         }|d         dk    r|                     |d          }	|	 n6|	|d<   |||d	<   |                     |d          }| 	                    | 
                    ||                    }n|t          | j        d
z             |||d<   |d         |d<   |                     |d          }|                     |d          }|                     |dd          }|                     |g d          }|d         rd}|                     d|          \  }}|dn|}|dk    r|r+|                     | 
                    ||                    }n|r+|                     | 
                    ||                    }n|r+|                     | 
                    ||                    }nd|                     | 
                    ||                    }n9|dk    r|r+|                     | 
                    ||                    }n|r+|                     | 
                    ||                    }n|r+|                     | 
                    ||                    }n|                     | 
                    ||                    }n|d         rx|d         r|r+|                     | 
                    ||                    }nC|r+|                     | 
                    ||                    }n|r*|                     | 
                    ||                    }n|                     | 
                    ||                    }n|d         r|d         |d<   |r*|                     | 
                    ||                    }n|r*|                     | 
                    ||                    }nU|r*|                     | 
                    ||                    }n)|                     | 
                    ||                    }|                     |d          }tA          |tB                    s|                     |dg           }| "                    ||||          S )a*  
        :see: https://huobiapi.github.io/docs/spot/v1/en/#get-all-open-orders
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-current-unfilled-order-acquisition
        :see: 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.stop]: *contract only* if the orders are stop trigger orders or not
        :param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
        :param boolean [params.trailing]: *contract only* set to True if you want to fetch trailing stop orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r@   r0   r  rq  r   r  r  z- fetchOpenOrders() requires a symbol argumentr#  rQ  r  r  r  Fr  r   r$  r%  r   rB   rC   rj  r  r  )#r  r  r  r   rs  r,  r-  ru  rL  spotPrivateGetV1OrderOpenOrdersr'  r   r0   r  rF  r+  7contractPrivatePostLinearSwapApiV1SwapTriggerOpenorders4contractPrivatePostLinearSwapApiV1SwapTpslOpenorders5contractPrivatePostLinearSwapApiV1SwapTrackOpenorders0contractPrivatePostLinearSwapApiV1SwapOpenorders<contractPrivatePostLinearSwapApiV1SwapCrossTriggerOpenorders9contractPrivatePostLinearSwapApiV1SwapCrossTpslOpenorders:contractPrivatePostLinearSwapApiV1SwapCrossTrackOpenorders5contractPrivatePostLinearSwapApiV1SwapCrossOpenorders1contractPrivatePostSwapApiV1SwapTriggerOpenorders.contractPrivatePostSwapApiV1SwapTpslOpenorders/contractPrivatePostSwapApiV1SwapTrackOpenorders*contractPrivatePostSwapApiV1SwapOpenorders1contractPrivatePostApiV1ContractTriggerOpenorders.contractPrivatePostApiV1ContractTpslOpenorders/contractPrivatePostApiV1ContractTrackOpenorders*contractPrivatePostApiV1ContractOpenordersr  rD  r  )r  r  r  r  r	  r  r(  r
  r  rp  r1  rl  r  r  r  r0  r  s                    r  fetch_open_orderszhtx.fetch_open_orders  s    	[[((F
!??@QSY[abb
F!$*4L!((>>I ""$$$q#dm"4"455 " "A"mA.Gv&00$($4$4Wd$C$C	$0!E$-GL! "'YYv|44F;;DKKQW<X<XYYHH~'2a(abbb ',$'-d|GO$??6622D!%9M!N!N~~fj%@@HYYv'Q'Q'QRRFh )q!
%)%G%GHY[a%b%b"
F)3);WW*
++ w#'#_#_`d`k`klsu{`|`|#}#}+ w#'#\#\]a]h]hiprx]y]y#z#z! w#'#]#]^b^i^ijqsy^z^z#{#{#'#X#XY]YdYdelntYuYu#v#v7** |#'#d#deiepepqx  {A  fB  fB  $C  $C+ |#'#a#abfbmbmnuw}b~b~##! |#'#b#bcgcncnovx~cc  $A  $A#'#]#]^b^i^ijqsy^z^z#{#{	" q&> q q#'#Y#YZ^ZeZefmouZvZv#w#w+ q#'#V#VW[WbWbcjlrWsWs#t#t! q#'#W#WX\XcXcdkmsXtXt#u#u#'#R#RSWS^S^_fhnSoSo#p#pH% 	q(.z(:GH% q#'#Y#YZ^ZeZefmouZvZv#w#w+ q#'#V#VW[WbWbcjlrWsWs#t#t! q#'#W#WX\XcXcdkmsXtXt#u#u#'#R#RSWS^S^_fhnSoSo#p#pr 622&$'' 	;__VXr::F  >>>r  c                 R    ddddddddddddddd}|                      |||          S )Nr  canceledclosed	canceling)zpartial-filledzpartial-canceledfilledr  	submittedrt  r]  23456711r   r  r   statusess      r  parse_order_statuszhtx.parse_order_status  sT     % *"!
 
$ &&999r  c           
      *   |                      |dd          }|                     |                      |dd                    }|d}|                     |g d          }|                     |d          }|                     |d          }d	|v r+|d	                             d
          }|d         }|d         }|                      |dd          }	|                     |	|          }|                     |g d          }
|                      |dd          }d }d }|M|                    d          dk    r4|dk    r|                     |d          }nF|                     |d          }n/|                      |dd          }|                     |g d          }|                     |g d          }|                      |dd          }|                      |dd          }|                     |d|          }d }|Kd }|                     |d          }||                     |          }n|dk    r|d         n|d          }||d!}|                      |d"d#          }|                     |d$          }| 	                    |d%          }| 
                    |d&          }d }|
|dk    rd'nd(}|                     i d)|d*|d+|d,|
d-|                     |
          d.d d|d         d	|d/d d0d d1|d|d2|d3|d4|d5|d||d ||||d6|          S )7Nerr_codeerr-coderZ  r   rejected)r0   order_id_strr  r  order_price_typer  rS  r   r   rQ  r  )r  r  r_  r  client-order-idr  sellfield-cash-amountr7  volume)zfilled-cash-amountr(  r  )r  zfield-amountr  rl  order_pricer  z
field-feesr!  r  rf  re  r   
stop-pricetrigger_pricetrade_avg_pricer'  reduce_onlyFTr  r0   r  r  r  lastTradeTimestamptimeInForcepostOnlyr  	stopPricetriggerPricer  r>  )r  	remainingr   
reduceOnlyr!  r'  )r  r  r  r   r|  r  safe_integer_nfindr~  r  r  
safe_orderr  )r  r  r  rejectedCreateOrdersr   r0   r  r  	orderTyper"  r  r  r>  r7  r  rl  r  r!  r  r  r2  r  r'  reduceOnlyIntegerr5  s                            r  r  zhtx.parse_order  s   N  $11%ZPP((););E7H)U)UVV+F'I'I'IJJ{33'9::U??f++C00IQ<DQ<D%%e_hGG!!(F33''/Z/Z/Z[[	**52CE[\\499X#6#6!#;#;v~~''/BCC''x88''xBBF%%e-j-j-jkkD##E+\+\+\]]""5'=AA$$UM<HH""5%99K ,,UK@@M("55mDD26&..fWoovf~' C &&ulOLL	""5*;<<11 --e]CC
(#4#9#9J  
E 
" 
 ] 
 	 

 Y// 
 !$ 
 fX& 
 D 
 4 
  
 D 
 U 
  
 I 
 w 
  D! 
" f# 
$ $/ 
  
  
0 1  	r  r>  c                     |                                   |                     |          }|d         st          | j        dz             d|d<   |                     |dd|d|          S )a  
        create a market buy order by providing the symbol and cost
        :see: 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>`
        r@   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r  buyN)r  r  r$   r0   create_order)r  r  r>  r	  r  s        r  !create_market_buy_order_with_costz%htx.create_market_buy_order_with_cost  ss     	V$$f~ 	ftw)ddeee6;23  5$fMMMr  r  r  r7  rl  c	                     |t          | j        dz             |t          | j        dz             ||d<   ||d<   |                     ||||||          S )a  
        create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency, or number of contracts
        :param float [price]: the price for the order to be filled at, in units of the quote currency, ignored in market orders
        :param float trailingPercent: the percent to trail away from the current market price
        :param float trailingTriggerPrice: the price to activate a trailing order, default uses the price argument
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NzA createTrailingPercentOrder() requires a trailingPercent argumentzF createTrailingPercentOrder() requires a trailingTriggerPrice argumenttrailingPercenttrailingTriggerPrice)r   r0   r>  )	r  r  r  r  r7  rl  rA  rB  r	  s	            r  create_trailing_percent_orderz!htx.create_trailing_percent_order  sp     "#DG.q$qrrr'#DG.v$vwww$3 !)=%&  tVUFKKKr  c                    |                                   |                                  |                     |          }d}|                     d|          \  }}|                     |d         ||          }	|	|d         d}
|                    dd          }|                    dd          }|                     | j        |d         i           }|                     |d	d
          }|3|                     |di           }||v rt          | j
        dz             nz|dk    rdnd}|                     |d|          }|                     ||          |
d
<   ||
d<   |dk    s|dk    rd|z   }n)|dk    r#|dk    rt          | j
        dz   |z   dz             d}|                     |dk    |dk    |          \  }}|rd}|                     |dd          }|dk    r|dz   }n|dk    rd}|d z   |z   |
d<   |                     |d!d"          }|M|                     | j        d#i           }|                     |d          }||                                 z   |
d"<   n||
d"<   |d$k    rd%|
d&<   n|d'k    rd(|
d&<   n|d)k    rd*|
d&<   |dk    r|d+k    rd}d,}|                     |dd-d,          \  }}|                     |d.          }|                     |d.          }||                     ||          }n|rm|t)          | j
        d/z             |                     |          }|                     |          }|                     |t-          j        ||                    }n|                     ||          }||
d0<   n|                     ||          |
d0<   |                     |d1i           }||v r|                     ||          |
d2<   |                     |g d3          }|                     |
|          S )4a  
         * @ignore
        helper function to build request
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.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
        NrO   r  r0   )rq  r  zbuy- zsell-r2  r+  r  zN createOrder() requires a stopPrice or a stop-price parameter for a stop orderr'  ltegteoperatorr  r  zstop-r  r  z  createOrder() does not support r  r  r  r0  r  FOKz-fokIOCr  rS  r  r&  r  r$  zsuper-margin-apisourcer%  z
margin-apic2czc2c-margin-apir=  Tr  r>  z createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argumentr7  r  rl  )r2  r+  r  r&  rH  r0  )r  rs  r  r+  rx  replacer  r   r  r   r0   r   price_to_precisionr$   handle_post_onlyuuidrC  r   rL  amount_to_precisionr"   number_to_stringr,   
string_mulr'  )r  r  r  r  r7  rl  r	  r  r0  rp  r(  r:  r   r2  r  defaultOperatorstopOperatorr1  r0  r  r  brokerIdquoteAmountr  r>  r  r  r  s                               r  create_spot_order_requestzhtx.create_spot_order_request  s    	V$$
!??vVV
F11&.*fUU	 $Tl
 
 LL,,	%%gr22	//$,vCC&&v{LII	!__W6FKKNN**'  3C  )C  D  D  D + )-eeUO++FJPPL$($;$;FI$N$NGL!".GJW$$){*B*B#i/		|++)?O2O2O"47-O#ORV#VYb#bccc00h1F	UbHbdjkk& 	&%I&&v}eDD%!F*IIE!!I*y0**6?DUVV __T\8R@@F''55H)1DIIKK)?G%&&)6G%&   2GH:%% ,GH5   0GH!!K04-8<8U8UV\^k  nQ  SW  9X  9X5-v##FF33DYYvv..F"66vtDD2 G=&tw  2m  (m  n  n  n $(#8#8#@#@L"&"7"7">">K"&":":67CUVbdoCpCp"q"qKK"66vvFF +GH $ 8 8 H HGH//'3DbII''#66vuEEGG6#}#}#}~~{{7F+++r  c                 p   |                      |          }|d         |                     ||          |d}d}	|                     |dk    |dk    |          \  }	}|	rd}|                     |dd          }
|
dk    rd	}n|
d
k    rd}|                     |dd          }|                     |dd          }|                     |dd          }|                     |dd          }|                     |d|          }|du}|du}|du}|du}|rS|                     |ddd          }||d<   |                     ||          |d<   ||                     ||          |d<   n/|s|rv|r:||d<   |                     ||          |d<   ||                     ||          |d<   n||d<   |                     ||          |d<   ||                     ||          |d<   n|rMt          j	        |d          }| 
                    |          |d<   ||d<   |                     |dd           |d<   nf|                     |d!d"          }|||d!<   |                     |d"g          }|d#k    s|dk    s|d	k    s|dk    r|                     ||          |d$<   |sD|sB|                     |d%d&d'          }|rd(|d&<   |                     |g d)d(          |d*<   |s||d<   |                     | j        d+i           }|                     |d          }||d,<   |                     |g d-          }|                     ||          S ).a  
         * @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 fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.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
        r0   )rQ  r)  r  Nr  	post_onlyr0  r  rI  fokrJ  r  r2  r,  stopLossPricesl_trigger_pricetakeProfitPricetp_trigger_pricerA  callback_raterB  triggerTypetrigger_typeler*  sl_order_price_typesl_order_pricetp_order_price_typetp_order_price100active_pricer%  formula_pricer  r  r  rl  r5  r.  Fr   )	leverRate
lever_ratern  rl  r  channel_code)
r5  r2  r\  r^  ra  rk  r0  rn  rA  rB  )r  rQ  rO  r   safe_number_2r  r   rN  r,   
string_divparse_to_numericr  rL  rt  r6  r  r   r'  )r  r  r  r  r7  rl  r	  r  r(  r1  r0  r3  stopLossTriggerPricetakeProfitTriggerPricerA  rB  isTrailingPercentOrderisStopisStopLossTriggerOrderisTakeProfitTriggerOrderra  trailingPercentStringr  r5  r  rV  s                             r  create_contract_order_requestz!htx.create_contract_order_request#  s3    V$$#D\..vv>>
 

 001A4;CVX^__& 	D&&v}eDD%DDE!!D))&+OO#11&/K]^^!%!3!3F<MOa!b!b,,V5FXX#//8NPUVV!0!<T)!5T!A#9#E  	J,,V]NTXYYK&1GN#'+'>'>v|'T'TGO$ )-)@)@)O)O&# 	J'? 	J% 	W15-..2.E.EfNb.c.c*+$040G0GPU0V0VG,-15-..2.E.EfNd.e.e*+$040G0GPU0V0VG,-# 	J$+$6$N$N!'+'<'<=R'S'SGO$&:GN#*.*:*:6CUWf*g*gG&'' //8I?[[M(-:)*6O+<==w$%--45==DKDWDW#'#:#:65#I#I % 	3.F 	3**6<PUVVJ +)*&$($7$7@g@g@gij$k$kGL!) 3.2*+x<<##FD11"*6  $E  $E  $E  F  F{{7F+++r  c                    |                                   |                     |          }|                     |dd          }|                     |dd          }	|                     |dd          }
|                     |d          }|du}|du}|	du}|
du}d}|d	         rJ|rt	          | j        d
z             |                     ||||||          }|                     |          }n|                     ||||||          }|d         rd}| 	                    d|          \  }}|dn|}|dk    rd|r| 
                    |          }n|s|r|                     |          }no|r|                     |          }nV|                     |          }n?|dk    ra|r|                     |          }n |s|r|                     |          }n|r|                     |          }n|                     |          }n|d         r|d         r`|r|                     |          }n|s|r|                     |          }n|r|                     |          }n}|                     |          }ng|d         r_|r|                     |          }nG|s|r|                     |          }n-|r|                     |          }n|                     |          }d}d}|d	         ra|                     i d|d|                     |d          ddddddddddd|d|d|d|ddddd dd!dd"dd#dd$di|          S |r/|                     |di           }|                     |d%i           }nH|r/|                     |di           }|                     |d&i           }n|                     |di           }|                     ||          S )'a  
        create a trade order
        :see: https://huobiapi.github.io/docs/spot/v1/en/#place-a-new-order                   # spot, margin
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-an-order        # coin-m swap
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-trigger-order   # coin-m swap trigger
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-an-order           # usdt-m swap cross
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-trigger-order      # usdt-m swap cross trigger
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-an-order        # usdt-m swap isolated
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-trigger-order   # usdt-m swap isolated trigger
        :see: https://huobiapi.github.io/docs/dm/v1/en/#place-an-order                        # coin-m futures
        :see: 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 fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.stopPrice]: 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* 'open', 'close', or 'both', required in hedge mode
        :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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r2  r,  r\  r]  r^  r_  rA  Nr@   z@ createOrder() does not support trailing orders for spot marketsr   rO   r$  r%  r   rB   rC   r  r0   r  r  r  r/  r   r  r  r  rl  r7  r  r4  r>  r'  r!  r  r  sl_ordertp_order)r  r  rn  r   r$   r0   rX  !spotPrivatePostV1OrderOrdersPlacerx  r+  2contractPrivatePostLinearSwapApiV1SwapTriggerOrder/contractPrivatePostLinearSwapApiV1SwapTpslOrder0contractPrivatePostLinearSwapApiV1SwapTrackOrder+contractPrivatePostLinearSwapApiV1SwapOrder7contractPrivatePostLinearSwapApiV1SwapCrossTriggerOrder4contractPrivatePostLinearSwapApiV1SwapCrossTpslOrder5contractPrivatePostLinearSwapApiV1SwapCrossTrackOrder0contractPrivatePostLinearSwapApiV1SwapCrossOrder,contractPrivatePostSwapApiV1SwapTriggerOrder)contractPrivatePostSwapApiV1SwapTpslOrder*contractPrivatePostSwapApiV1SwapTrackOrder%contractPrivatePostSwapApiV1SwapOrder,contractPrivatePostApiV1ContractTriggerOrder)contractPrivatePostApiV1ContractTpslOrder*contractPrivatePostApiV1ContractTrackOrder%contractPrivatePostApiV1ContractOrderr8  r   r  r  )r  r  r  r  r7  rl  r	  r  r3  rq  rr  rA  rs  rt  ru  rv  r  spotRequestcontractRequestr0  r  r0  s                         r  r>  zhtx.create_ordert  sU   @ 	V$$))&+OO#11&/K]^^!%!3!3F<MOa!b!b**63DEE!0!<T)!5T!A#9#E &> /	_% q"47-o#oppp88tVUZ\bccK==kJJHH"@@tU[]bdjkkOh (_!
.2.P.PQ^`o.p.p+
O)3);WW*
++ e#'#Z#Z[j#k#k/ e3K e#'#W#WXg#h#h/ e#'#X#XYh#i#i#'#S#STc#d#d7** j#'#_#_`o#p#p/ j3K j#'#\#\]l#m#m/ j#'#]#]^m#n#n#'#X#XYh#i#i	" _&> _ _#'#T#TUd#e#e/ _3K _#'#Q#QRa#b#b/ _#'#R#RSb#c#c#'#M#Mo#^#^H% _ _#'#T#TUd#e#e/ _3K _#'#Q#QRa#b#b/ _#'#R#RSb#c#c#'#M#Mo#^#^> &> 	;?? $$d&&x88$ T$ D	$
 %d$ $$ $$ $ $ $ &$ $$ T$ $ $$  t!$"  #$$ 4%$ $& '  ( $ 	;??8VR88D__T:r::FF% 	;??8VR88D__T:r::FF__Xvr::F///r  r  c           	         |                                   g }d}d}d}t          dt          |                    D ]s}||         }|                     |d          }	||	}n||	k    rt	          | j        dz             |                     |d          }
|                     |d          }|                     |d          }|                     |d          }|                     |d	i           }|                     d
|          }|d         }|"||}n||k    rt	          | j        dz             |                     |          }d}|d         r| 	                    |	|
||||          }n| 
                    |	|
||||          }|                     |d          }|                    |           ui }d}|d         r|                     |          }n||d<   |d         r>|dn|}|dk    r|                     |          }n_|dk    r|                     |          }nC|d         r;|d         r|                     |          }n|d         r|                     |          }d}|d         r|                     |dg           }n[|                     |di           }|                     |dg           }|                     |dg           }|                     ||          }|                     ||          S )aK  
        create a list of trade orders
        :see: https://huobiapi.github.io/docs/spot/v1/en/#place-a-batch-of-orders
        :see: https://huobiapi.github.io/docs/dm/v1/en/#place-a-batch-of-orders
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-a-batch-of-orders
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-a-batch-of-orders
        :see: 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 symbolr  r  r7  rl  r	  rP   zS createOrders() requires all orders to have the same margin mode(isolated or cross)r@   r0  orders_datar   r$  r%  r   rB   rC   r  successerrors)r  r,  r-  r   r   r0   r  r+  r  rX  rx  rL  rG  privatePostOrderBatchOrders0contractPrivatePostLinearSwapApiV1SwapBatchorder5contractPrivatePostLinearSwapApiV1SwapCrossBatchorder*contractPrivatePostSwapApiV1SwapBatchorder*contractPrivatePostApiV1ContractBatchorderrI  r  )r  r  r	  ordersRequestsr  r  r0  r1  rawOrderr"  r  r  r7  rl  orderParamsmarginResultcurrentMarginModeorderRequestr(  r  r0  r  r  r  s                           r  create_orderszhtx.create_orders  se    	
q#f++&& 	0 	0AayH''(;;H~!X%%$TW/l%lmmm##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAK==nkZZL ,Q ,%!2JJ!%666(  4I  *I  J  J  J[[((FLf~ t#==hdTZ\acnoo#AA(DRVX^`egrss99\<@@L!!,////&> 	X77GGHH%3GM"h 
X)3);WW*
++#TTU\]]HH7**#YYZabbH	" X&> X#NNwWWHHH% X#NNwWWHT &> 	8__Xvr::FF??8VR88DoodIr::G__T8R88F&&w77F  000r  c                 
   |                                   d}||                     |          }d}|                     d||          \  }}i }d}|dk    r|                     |dd          }|0||d<   |                     |                     ||                    }nE||d<   |                     |ddg          }|                     |                     ||                    }n|t          | j	        dz             |                     |dd          }|||d	<   n||d<   |                     |ddg          }|d
         r|d         |d<   n|d         |d<   | 
                    |d          }	| 
                    |d          }
|                     |dd          }|                     |g d          }|d         rd}|                     d|          \  }}|dn|}|dk    r|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }n|r+|                     |                     ||                    }nw|                     |                     ||                    }nL|dk    r|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }n|r+|                     |                     ||                    }n|                     |                     ||                    }n|d         rn|d         r|	r+|                     |                     ||                    }nV|
r+|                     |                     ||                    }n)|r*|                     |                     ||                    }n|                     |                     ||                    }n|d
         r|	r*|                     |                     ||                    }n|
r*|                     |                     ||                    }ns|r*|                     |                     ||                    }nG|                     |                     ||                    }nt;          | j	        dz   |z   dz             |                     |                     ||          |dd          S )a  
        cancels an open order
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.stop]: *contract only* if the order is a stop 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>`
        NrI   r@   r&  r  r  z) cancelOrder() requires a symbol argumentr  r  rC   rj  r  r0   rQ  r  r  r  Fr  r   r$  r%  r   rB   z  cancelOrder() does not support r&  r  )r0   r   )r  r  r  r  /spotPrivatePostV1OrderOrdersOrderIdSubmitcancelr'  rL  3spotPrivatePostV1OrderOrdersSubmitCancelClientOrderr   r0   r  rF  r+  3contractPrivatePostLinearSwapApiV1SwapTriggerCancel0contractPrivatePostLinearSwapApiV1SwapTpslCancel1contractPrivatePostLinearSwapApiV1SwapTrackCancel,contractPrivatePostLinearSwapApiV1SwapCancel8contractPrivatePostLinearSwapApiV1SwapCrossTriggerCancel5contractPrivatePostLinearSwapApiV1SwapCrossTpslCancel6contractPrivatePostLinearSwapApiV1SwapCrossTrackCancel1contractPrivatePostLinearSwapApiV1SwapCrossCancel-contractPrivatePostSwapApiV1SwapTriggerCancel*contractPrivatePostSwapApiV1SwapTpslCancel+contractPrivatePostSwapApiV1SwapTrackCancel&contractPrivatePostSwapApiV1SwapCancel-contractPrivatePostApiV1ContractTriggerCancel*contractPrivatePostApiV1ContractTpslCancel+contractPrivatePostApiV1ContractTrackCancel&contractPrivatePostApiV1ContractCancelr$   r  )r  r0   r  r	  r  r
  r(  r  r  r  r  r  r0  s                r  cancel_orderzhtx.cancel_order  s    	[[((F
!??vW]^^
F
  ..v7H/ZZM$&(
#OOPTP[P[\cekPlPlmm-:)*6,=+OPPSSTXT_T_`gioTpTpqq~'2](]^^^ ..v7H/ZZM$&(
##-:)*6,=+OPPh 8$*:$6!!+1$<(??6622D!%9M!N!N~~fj%@@HYYv'Q'Q'QRRFh *k!
%)%G%GW]%^%^"
F)3);WW*
++ s#'#[#[\`\g\ghoqw\x\x#y#y+ s#'#X#XY]YdYdelntYuYu#v#v! s#'#Y#YZ^ZeZefmouZvZv#w#w#'#T#TUYU`U`ahjpUqUq#r#r7** x#'#`#`aealalmtv|a}a}#~#~+ x#'#]#]^b^i^ijqsy^z^z#{#{! x#'#^#^_c_j_jkrtz_{_{#|#|#'#Y#YZ^ZeZefmouZvZv#w#w	" k&> m m#'#U#UVZVaVabikqVrVr#s#s+ m#'#R#RSWS^S^_fhnSoSo#p#p! m#'#S#STXT_T_`gioTpTp#q#q#'#N#Nt{{[bdjOkOk#l#lH% m m#'#U#UVZVaVabikqVrVr#s#s+ m#'#R#RSWS^S^_fhnSoSo#p#p! m#'#S#STXT_T_`gioTpTp#q#q#'#N#Nt{{[bdjOkOk#l#l"47-O#OR\#\_i#ijjj( {{4++Hf== @
 @
   	r  c                    |                                   d}||                     |          }d}|                     d||          \  }}i }d}|dk    r|                     |dd          }|                     |dd|          }|"t	          |t
                    r|g|d<   n?||d<   n9t	          |t
                    r|g|d<   n||d<   |                     |g d	          }|                     |                     ||                    }n]|t          | j
        d
z             |                     |dd          }|                     |dd|          }|d                    |          |d<   n||d<   |                     |g d          }|d         r|d         |d<   n|d         |d<   |                     |d          }	|                     |d          }
|                     |ddg          }|d         r7d}|                     d|          \  }}|dn|}|dk    r|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }n|                     |                     ||                    }n|dk    r|	r+|                     |                     ||                    }n|
r+|                     |                     ||                    }ne|                     |                     ||                    }n:|d         r|d         r|	r*|                     |                     ||                    }n|
r*|                     |                     ||                    }n|                     |                     ||                    }n|d         r|	r*|                     |                     ||                    }ns|
r*|                     |                     ||                    }nG|                     |                     ||                    }nt7          | j
        dz   |z   dz             |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.stop]: *contract only* if the orders are stop 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>`
        NrJ   r@   r&  r  client-order-idsclientOrderIdsz	order-ids)r&  r  r  r  z* cancelOrders() requires a symbol argumentr  client_order_ids,r  )r  r  r  r  rC   rj  r  r0   rQ  r  r  r   r$  r%  r   rB   z! cancelOrders() does not support r&  )r  r  r  rt  r  strrL  'spotPrivatePostV1OrderOrdersBatchcancelr'  r   r0   r  joinr  r+  r  r  r  r  r  r  r  r  r  r  r  r  r$   )r  idsr  r	  r  r
  r(  r  r  r  r  r0  s               r  cancel_orderszhtx.cancel_orders  s    	[[((F
!??PVX^__
F	
 !..v7H/ZZN!..v7IK[]kllN%nc22 /,/5GK((+.GK((nc22 A3A2BG.//2@G./6+u+u+uvvCCDKKPWY_D`D`aaHH~'2^(^___!//8I?[[N!//8JL\^lmmN%&)hhsmm
##-;)*6+u+u+uvvh 8$*:$6!!+1$<(??6622D!%9M!N!NYYv0D'EFFFh "l!
%)%G%GX^%_%_"
F)3);WW*
++ s#'#[#[\`\g\ghoqw\x\x#y#y+ s#'#X#XY]YdYdelntYuYu#v#v#'#T#TUYU`U`ahjpUqUq#r#r7** x#'#`#`aealalmtv|a}a}#~#~+ x#'#]#]^b^i^ijqsy^z^z#{#{#'#Y#YZ^ZeZefmouZvZv#w#w	" l&> m m#'#U#UVZVaVabikqVrVr#s#s+ m#'#R#RSWS^S^_fhnSoSo#p#p#'#N#Nt{{[bdjOkOk#l#lH% m m#'#U#UVZVaVabikqVrVr#s#s+ m#'#R#RSWS^S^_fhnSoSo#p#p#'#N#Nt{{[bdjOkOk#l#l"47-P#PS]#]`j#jkkkh r  c                    |                                   d}||                     |          }d}|                     d||          \  }}i }d}|dk    r8||d         |d<   |                     |                     ||                    }n|t          | j        dz             |d         r|d         |d<   |d         |d	<   |                     |d
          }|                     |d          }|                     |dd          }	| 	                    |g d          }|d         rd}
| 
                    d|          \  }
}|
dn|
}
|
dk    r|r+|                     |                     ||                    }n|r+|                     |                     ||                    }n|	r+|                     |                     ||                    }nw|                     |                     ||                    }nL|
dk    r|r+|                     |                     ||                    }n|r+|                     |                     ||                    }n|	r+|                     |                     ||                    }n|                     |                     ||                    }n|d         rn|d         r|r+|                     |                     ||                    }nV|r+|                     |                     ||                    }n)|	r*|                     |                     ||                    }n|                     |                     ||                    }n|d         r|r*|                     |                     ||                    }n|r*|                     |                     ||                    }ns|	r*|                     |                     ||                    }nG|                     |                     ||                    }nt7          | j        dz   |z   dz             |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.stop]: *contract only* if the orders are stop 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>`
        NrH   r@   r0   r  z- cancelAllOrders() requires a symbol argumentrC   rj  rQ  r  r  r  Fr  r   r$  r%  r   rB   z$ cancelAllOrders() does not support r&  )r  r  r  1spotPrivatePostV1OrderOrdersBatchCancelOpenOrdersr'  r   r0   r  rF  rL  r+  6contractPrivatePostLinearSwapApiV1SwapTriggerCancelall3contractPrivatePostLinearSwapApiV1SwapTpslCancelall4contractPrivatePostLinearSwapApiV1SwapTrackCancelall/contractPrivatePostLinearSwapApiV1SwapCancelall;contractPrivatePostLinearSwapApiV1SwapCrossTriggerCancelall8contractPrivatePostLinearSwapApiV1SwapCrossTpslCancelall9contractPrivatePostLinearSwapApiV1SwapCrossTrackCancelall4contractPrivatePostLinearSwapApiV1SwapCrossCancelall0contractPrivatePostSwapApiV1SwapTriggerCancelall-contractPrivatePostSwapApiV1SwapTpslCancelall.contractPrivatePostSwapApiV1SwapTrackCancelall)contractPrivatePostSwapApiV1SwapCancelall0contractPrivatePostApiV1ContractTriggerCancelall-contractPrivatePostApiV1ContractTpslCancelall.contractPrivatePostApiV1ContractTrackCancelall)contractPrivatePostApiV1ContractCancelallr$   )r  r  r	  r  r
  r(  r  r  r  r  r0  s              r  cancel_all_orderszhtx.cancel_all_orders  s    	[[((F
!??@QSY[abb
F
 !$*4L!MMdkkZaciNjNjkkHH~'2a(abbbh 7$*:$6!'-d|GO$??6622D!%9M!N!N~~fj%@@HYYv'Q'Q'QRRFh *o!
%)%G%GHY[a%b%b"
F)3);WW*
++ v#'#^#^_c_j_jkrtz_{_{#|#|+ v#'#[#[\`\g\ghoqw\x\x#y#y! v#'#\#\]a]h]hiprx]y]y#z#z#'#W#WX\XcXcdkmsXtXt#u#u7** {#'#c#cdhdodopwy  eA  eA  $B  $B+ {#'#`#`aealalmtv|a}a}#~#~! {#'#a#abfbmbmnuw}b~b~###'#\#\]a]h]hiprx]y]y#z#z	" o&> p p#'#X#XY]YdYdelntYuYu#v#v+ p#'#U#UVZVaVabikqVrVr#s#s! p#'#V#VW[WbWbcjlrWsWs#t#t#'#Q#QRVR]R]^egmRnRn#o#oH% p p#'#X#XY]YdYdelntYuYu#v#v+ p#'#U#UVZVaVabikqVrVr#s#s! p#'#V#VW[WbWbcjlrWsWs#t#t#'#Q#QRVR]R]^egmRnRn#o#o"47-S#SV`#`cm#mnnn0 r  r  c                    |                      |d          }|                      |d          }|                      |d          }|                     ||          }|                     ||          }|                      |d          }|                      |d          }|                     |           ||||                     |          ||dS )Naddress
addressTagr  noter  )r  r  tagr  r  r  )r   r  r~  check_addressr  )	r  depositAddressr  r  r  r  rk  r  r  s	            r  parse_deposit_addresszhtx.parse_deposit_address  s     "">9==~|<<%%njAA
%%j(;;&&z8<<77$$^W==	7###..y99"
 
 	
r  rk  c                 P   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     ||d         gd          }|                     |d          S )a  
        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  r0   r  rk  Fr  )r  r  %spotPrivateGetV2AccountDepositAddressr'  r  parse_deposit_addressesindex_by)r  rk  r	  r  r(  r  r  parseds           r  "fetch_deposit_addresses_by_networkz&htx.fetch_deposit_addresses_by_network  s     	==&&
 ==dkk'SY>Z>Z[[ x44--dXf5E4FNN}}VY///r  c                     |                                   |                     |          }|                     |          \  }}|                     ||          }|                     |d         ||          }||         S )a9  
        fetch the deposit address for a currency associated with self account
        :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>`
        rk  )r  r  handle_network_code_and_paramsr  )select_network_code_from_unified_networks)r  rk  r	  r  r  paramsOmitedindexedAddressesselectedNetworkCodes           r  fetch_deposit_addresszhtx.fetch_deposit_address7  s     	==&&$($G$G$O$O!\BB4VV"LLXV\M]_jl|}} 344r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     ||d         gd          }	g }
t          dt          |	                    D ]C}|	|         }|d u p|d         |k    }|d u p|d         |k    }|r|r|
                    |           D|
S )	Nr  r0   r  rk  Fr   r  r  )	r  r  &spotPrivateGetV2AccountWithdrawAddressr'  r  r  r,  r-  rG  )r  rk  r  r  r	  r  r(  r  r  allAddresses	addressesr1  r  	noteMatchnetworkMatchs                  r  fetch_withdraw_addresseszhtx.fetch_withdraw_addressesE  s   ==&&
 >>t{{7TZ?[?[\\ x4433D8F;K:LeTT	q#l++,, 	* 	*A"1oGC76?d+BI'4/WWY5G;5VL *\ *  )))r  c                 2   ||dk    rd}|                                   d}||                     |          }dddd}||d         |d<   |||d	<   |                     |                     ||                    }|                     |d
         |||          S )a  
        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>`
        Nr6   r  nextr   r  directrE  r0   r  r  r  r  r  $spotPrivateGetV1QueryDepositWithdrawr'  parse_transactionsr  rk  r  r  r	  r  r(  r  s           r  fetch_depositszhtx.fetch_depositse  s     =ECKKE}}T**H
 

 "*4.GJ#GFO<<T[[RX=Y=YZZ6 &&x'75%PPPr  c                 2   ||dk    rd}|                                   d}||                     |          }dddd}||d         |d<   |||d	<   |                     |                     ||                    }|                     |d
         |||          S )a  
        fetch all withdrawals made from an account
        :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>`
        Nr6   r   r  r   r  r0   r  r  r  r  r  s           r  fetch_withdrawalszhtx.fetch_withdrawals  s     =ECKKE}}T**H
 

 "*4.GJ#GFO<<T[[RX=Y=YZZ2 &&x'75%PPPr  c                    |                      |d          }|                     |                     |d                    }|                     |d          }|dk    rd}|                     |d          }|t          j        |          }|                     |d          }|                     |d          }|d	k    r|                    d
          dk     rd
|z   }|                     |d          }	|	dk    }
i d|d|                     |dd          d|d|d|                     |          d|                     |          d|                     |d          dd dd d|                     |d          dd dd d|d| 	                    |d          d|d| 
                    |                     |d                    d|                      |d           d |
||                     |          d d!d"S )#Nr  r  r  r   
withdrawalr!  r  ztx-hashr  0xr   zsub-typeFASTr  r0   r  txidr  r  r  r  	addressToaddressFromr  zaddress-tagtagTotagFromr7  r   rZ  r  z
updated-at)r  r>  rate)commentinternalr!  )r  r~  r   r,   
string_absr7  r  r  r  r   parse_transaction_statusr  )r  transactionr  r  rk  r  r  r  txHashr  r  s              r  parse_transactionzhtx.parse_transaction  s   f %%k<@@	&&t'7'7Z'P'PQQV44:D"";66(11G$$['::	!!+y99&++d"3"3a"7"7F]F"";
;;f$
K
$$$[$??
 F
 	

 Y//
 t..y99
 t''Y??
 
 4
 4##K??
 T
 t
 D
 d&&{H==
 
  d33D4D4D[RY4Z4Z[[!
" t((lCC#
$   ))'22 )
 
 
 	
r  c                 T    dddddddddddddddd}|                      |||          S )Nfailedpendingr  r  )unknown
confirming	confirmedsafeorphanr  r  	reexaminerejectpasszwallet-rejectzconfirm-errorrepealedzwallet-transferzpre-transferr  r  s      r  r  zhtx.parse_transaction_status)  sW      #"""%% (%%
 
( &&999r  c                    |                      ||          \  }}|                                  |                     |           |                     |          }||d                                         d}|||d<   d}|                     |          \  }}||                     ||          |d<   t          |                     |||                    }| 	                    | j
        di           }	|                     |	dd          r4|                     |d	          }
|
|                                 }|                     | j        |          | _        | 	                    |d
         |i           }|                     |d	          }
|
t!          | j        dz             |                     ||
|          }|                     |d	          }|                     |          }t)          j        ||          }t          |          }t          |          |d	<   t          |                     |||                    }||d<   |                     |                     ||                    }|                     ||          S )a  
        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>`
        r0   )r  r  Nzaddr-tagr  r   r   Fr!  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" parameterr7  )handle_withdraw_tag_and_paramsr  r  r  r{  r  r  floatcurrency_to_precisionr  r   rF  r   r  r  
currenciesr   r0   rL  rR  r,   
string_sub$spotPrivatePostV1DwWithdrawApiCreater'  r  )r  rk  r7  r  r  r	  r  r(  r  withdrawOptionsr!  r  targetNetwork	feeStringr  amountSubtractedStringamountSubtractedr  s                     r  r   zhtx.withdraw@  s    99#vFFV7###==&& ,,..
 
 ?"%GJ"AA&IIV"#66{DIIGGt11$LLMM//$,
BGG>>/<?? 	\""6511C{!2244
"&"2"24?J"O"O $0DkSU V V&&}e<<;+DG  7Y  -Y  Z  Z  Z224kJJIYYvu--F0088L%,%7i%P%P"$%;<<"9--GEN455d<LkZZ[[F"<<T[[RX=Y=YZZ %%h999r  c           
      r    |                      |d          }|                     d |          }||d d |d d d d d	S )Nr  )	r  r0   r  r  r  r7  fromAccount	toAccountr   )r   r~  )r  r   r  r0   rk  s        r  parse_transferzhtx.parse_transferu  sX     h//&&tX66

 

 
	
r  r!  r"  c                    |                                   |                     |          }|d         t          |                     ||                    d}d}|                     dd|          \  }}|                     |          }	|                     |          }
|
dk    }|	dk    }|                     |
| j                  }|                     |	| j                  }|	dk    }|
dk    }|r"|r t          | j	        dz   |z   dz   |z             |	d	k    p|
d	k    }d}|rO|	d
z   |
z   }| 
                    |d|          }||d<   |                     |                     ||                    }nd|r-|r+|                     |                     ||                    }n5|r-|r+|                     |                     ||                    }n|r1|r/|
|d<   |                     |                     ||                    }n|r1|r/|	|d<   |                     |                     ||                    }n|dk    r_|	dk    s|dk    rd}	nd}
| 
                    |d          }|                     |d          }||                     |          }||d<   nd|d<   |rdn|	|d<   |rdn|
|d<   |                     |                     ||                    }|                     ||          S )aA  
        transfer currency internally between wallets on the same account
        :see: https://huobiapi.github.io/docs/dm/v1/en/#transfer-margin-between-spot-account-and-future-account
        :see: https://huobiapi.github.io/docs/spot/v1/en/#transfer-fund-between-spot-account-and-future-contract-account
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-transfer-margin-between-spot-account-and-usdt-margined-contracts-account
        :see: https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-spot-trading-account-to-cross-margin-account-cross
        :see: https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-spot-trading-account-to-isolated-margin-account-isolated
        :see: https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-cross-margin-account-to-spot-trading-account-cross
        :see: 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>`
        r0   r  r7  Nr   r$  r=   z+ transfer() cannot make a transfer between z and r  z-to-r  r  r   rB   zlinear-swapzmargin-accountr	  r@   rE  rF  )r  r  r  r  r  convert_type_to_accountin_arrayr  r   r0   r    spotPrivatePostV1FuturesTransferr'   privatePostCrossMarginTransferIn!privatePostCrossMarginTransferOutprivatePostDwTransferInMarginprivatePostDwTransferOutMarginrL  r/  v2PrivatePostAccountTransferr#  )r  rk  r7  r!  r"  r	  r  r(  r  fromAccountIdtoAccountIdtoCross	fromCross
toIsolatedfromIsolatedfromSpottoSpotfromOrToFuturesAccountr  r  r  s                        r  r   zhtx.transfer  sg   & 	==&& D66tVDDEE
 
 99*dFSS44[AA229==(!W,	]];99
}}]DH== E)% 	z 	zTW'TTWbbelloxxyyy"/9"<![+QZBZ! 	W 6)K7D##FFD99D"GFO<<T[[RX=Y=YZZHH 	W' 	W<<T[[RX=Y=YZZHH 	W6 	W==dkk'SY>Z>Z[[HH 	W* 	W +GH99$++gv:V:VWWHH 	Wf 	W -GH::4;;wPV;W;WXXHH(""!V++1M1M$1MM"/K))&(;;6844%!^^F33F06G,--06G,-(0CffmGFO&,=FF+GDM88Wf9U9UVVH ""8X666r  c                 &   |                                   |                     |          }|                     |dg           }g }t          dt	          |                    D ]0}|                    |                     ||                              1|S )a  
        fetch the borrow interest rates of all currencies
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `isolated borrow rate structures <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
        r  r   )r  spotPrivateGetV1MarginLoanInfor  r,  r-  rG  parse_isolated_borrow_rate)r  r	  r  r  ratesr1  s         r  fetch_isolated_borrow_rateszhtx.fetch_isolated_borrow_rates  s     	66v>>< x44q#d))$$ 	C 	CALL88aAABBBBr  c           
         |                      |d          }|                     ||          }|                     |dg           }|                     |d          }|                     |d          }|                      |d          }|                      |d          }	||                     |          |                     |d          |                     |	          |                     |d          dd d |d	S )	Nr  r  r   r   r  zactual-ratei \&)	r  re  baseRaterf  	quoteRaterB  r  r  r  )r   r  r  r~  r   )
r  r  r  r"  r  r  baseData	quoteDatarh  ri  s
             r  r9  zhtx.parse_isolated_borrow_rate	  s    0 ##D(33!!(F33__T<<<
??:q11OOJ22	!!(J77""9j99++F33((=AA,,W55)))]CC

 

 
	
r  c                 \   |t          | j        dz             d}|                     |dd          \  }}|r|                     d||||dddd		  	        S |                                  |                     |          }d
|d         i}d}|d         r*|                     |                     ||                    }nI|d         r*|                     |                     ||                    }nt          | j        dz             | 
                    |d          }	| 
                    |	d          }
| 
                    |	dg           }g }t          dt          |                    D ]}||         }|
|d<   |                     |d
          }|                     |          }|                     |d          }|                    |||                     |d          ||                     |          d           |                     |d          }|                     ||d         ||          S )a  
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-historical-funding-rate
        :see: 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 argumentFro   r  
page_indexcurrent_pager   r   rQ  r0   r   r   zA fetchFundingRateHistory() supports inverse and linear swaps onlyr  r   funding_timefunding_rate)r  r  fundingRater  r  r  r  )r   r0   rC  fetch_paginated_call_cursorr  r  3contractPublicGetSwapApiV1SwapHistoricalFundingRater'  9contractPublicGetLinearSwapApiV1SwapHistoricalFundingRater$   r  r,  r-  r   r  r  rG  r   r  r9  r:  )r  r  r  r  r	  r  r  r(  r  r  cursorr0  r:  r1  r  r"  symbolInnerr  sorteds                      r  fetch_funding_rate_historyzhtx.fetch_funding_rate_history4  s~    >#DG.e$efff88AZ\fgg& 	R334MvW\^cekmy  |J  LM  OQ  R  R  RV$$VD\
 ) 	nOOPTP[P[\cekPlPlmmHHH 	nUUVZVaVabikqVrVrssHHtw)llmmm. x00~66vr22q#f++&& 	 	A1IE$*E.!''??H**844K))%@@ILL%#//~FF& LL33      e[11009I5RWXXXr  c                    |                      |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 S )Nestimated_raterD  next_funding_timerQ  r  r  	markPrice
indexPriceinterestRateestimatedSettlePricer  r  rF  rE  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)r   r  r   r  r  )r  r   r  rW  rU  rX  r"  r  s           r  parse_funding_ratezhtx.parse_funding_rate|  so     **85EFF,,X~FF#00;NOO##Ho>>!!(F33
H
f
 
 $	

 D
 #D
 
 
 4++HnEE
  0
 t||,<==
 
 #$8
 "4<<0D#E#E
 "4
  '!
" &t#
 	
r  c                    |                                   |                     |          }d|d         i}d}|d         r*|                     |                     ||                    }nI|d         r*|                     |                     ||                    }nt          | j        dz             |                     |di           }|                     ||          S )a  
        fetch the current 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>`
        rQ  r0   Nr   r   z: fetchFundingRate() supports inverse and linear swaps onlyr  )	r  r  )contractPublicGetSwapApiV1SwapFundingRater'  /contractPublicGetLinearSwapApiV1SwapFundingRater$   r0   r  r]  )r  r  r	  r  r(  r  r0  s          r  fetch_funding_ratezhtx.fetch_funding_rate  s     	V$$VD\
 ) 	gEEdkkRY[aFbFbccHHH 	gKKDKKX_agLhLhiiHHtw)eefff  6266&&vv666r  c                    |                                   |                     |          }|                     | j        di           }|                     | j        dd          }|                     |d|          }|                     |d|          }i }|                     |d          }d}|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j
        dz             |                     |dg           }|                     |          }	|                     |	d	|          S )
af  
        fetch the funding rate for multiple markets
        :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 `funding rates structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexe by market symbols
        rp   r  r   r  Nr   z1 fetchFundingRates() not support self market typer  r  )r  r  r  r   r   rL  4contractPublicGetLinearSwapApiV1SwapBatchFundingRater'  .contractPublicGetSwapApiV1SwapBatchFundingRater$   r0   parse_funding_ratesfilter_by_array)
r  r%  r	  r   r  r  r(  r  r  r0  s
             r  fetch_funding_rateszhtx.fetch_funding_rates  se    	%%g..//$,0CRHH))$,8H)TT""7I~FF""69g>>
 69--hPPQUQ\Q\]dflQmQmnnHH	!!JJ4;;W^`fKgKghhHHtw)\\]]]& x44))$//##FHg>>>r  c                 |   |                                   d}|                     d|          \  }}|dn|}i }||                     |          |d<   |||d<   d}d}	|dk    rL| |                     |          }|d         |d<   |                     |                     ||                    }	nK| |                     |          }
|
d         |d	<   |                     |                     ||                    }	|                     |	d
          }| 	                    ||          }| 
                    ||||          S )aO  
        fetch the interest owed by the user for borrowing currency for margin trading
        :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>`
        Nr\   r$  z
start-dater  r%  r0   r  r  r  )r  r+  yyyymmddr  privateGetMarginLoanOrdersr'  r  privateGetCrossMarginLoanOrdersr  parse_borrow_interestsfilter_by_currency_since_limit)r  rk  r  r  r  r	  r0  r(  r  r  r  r  interests                r  fetch_borrow_interestzhtx.fetch_borrow_interest  s]    	
!??@UW]^^
F!+!3WW*
$(MM%$8$8GL!#GFO##!V,,$*4L!66t{{7F7S7STTHH==..&.tn
#;;DKKQW<X<XYYH. x00..tV<<228T5%PPPr  c                    |                      |d          }|dnd}|                     |          }|                      |d          }|                     |d          }|dk    r|nd|||                     |                      |d                    |                     |d          |                     |d          |                     |d          ||                     |          |d	
S )
Nr  r$  r%  z
accrued-atr  zinterest-amountzinterest-ratezloan-amount)
rl  r  r0  r  rn  rS  amountBorrowedr  r  r  )r   r  r  r~  r   r  )r  r  r  r"  r0  r  r  s          r  parse_borrow_interestzhtx.parse_borrow_interest1  s    T ##D(33!)!1WW

!!(++!!&(33%%dL99	",
":":vv$//0@0@z0R0RSS((/@AA ,,T?CC"..t]CC"Y//
 
 	
r  r   r  c                 "   d}|                      ||                     |                    }t          |t                    r|dk    s|dk    r|| j        z  }n|dk    s|dk    r|dz  }|d|                     ||          z   z  }|dk    s|dk    rC|                                  |                     |                                 d          }	dd	| j	        |	d
}
|dk    r| 
                    |
|          }
|                     |
          }|                     |          }d                    || j        ||g          }|                     |                     |          |                     | j                  t$          j        d          }|d|                     d|i          z   z  }|d|z   z  }|dk    r|                     |          }ddi}n"ddi}n|r|d|                     |          z   z  }|                     | j        d         |         d| j        i          |z   }nd|                     |d          }|                     |d          }|                     |d          }|                     |d          }d }|                     | j        d         |          }t          |t                    sC|                     ||          }t          |t                    s||                     ||          }|}||                     ||          z  }|dk    r|r|d|                     |          z   z  }n%|dk    r|                                  |dk    r|                     | j        di           }|                     |dd          }|                    d          dk    r3|                    d           r|                     |d!          }|||d!<   nG|                    d"          r2|                     |d#          }|||                                 z   |d#<   |                     |                                 d          }	dd	| j	        |	d
}
|dk    r| 
                    |
|          }
|                     |
          }
|                     |
          }d                    ||||g          }|                     |                     |          |                     | j                  t$          j        d          }|d|                     d|i          z   z  }|d|z   z  }|dk    r/|                     |          }t9          |          dk    rd$}ddi}nddi}|                     | j        d         |         d|i          |z   }||||d%S )&NrV  r   r   r   r   v2T
HmacSHA256r  )SignatureMethodSignatureVersionAccessKeyId	TimestampPOST
base64&	Signature?zContent-Typezapplication/jsonz!application/x-www-form-urlencodedr   r<   r   r   r`  ra  r   r  r0   r  cancelr  rm  zorders/placer&  z{})r   r  bodyheaders)rL  extract_paramsr  r  r:   implode_paramscheck_required_credentialsymdhmsmillisecondsapiKeyr'  keysort	urlencoder  r<   hmacencodesecrethashlibsha256rz  r   r   r  r   r7  endswithrP  r-  )r  pathr   r  r	  r  r  r   queryr  r(  sortedRequestauthpayload	signaturer  accesslevelOneNestedPathlevelTwoNestedPathr<   r   r   r0   channelCoder  s                            r  signzhtx.signm  s   		&$"5"5d";";<<c3 f	xSI%5%5t|###););t3,,T6::::Ci3+#5#5//111 KK(9(9(;(;SAA	'3(+#';!*	  V##"kk'599G $W 5 5~~m44))VT]C$FGG IIdkk'&:&:DKK<T<TV]Vdfnoo	dnnk9-EFFFFsTz!V##99U++D&(:GG
 '(KGG  73!6!666C%%di&6s&;DM>  CC ##C++D%%c1--F!%!1!1#q!9!9!%!1!1#q!9!9H	+(>EEIi-- O OOI7IJJ	"9c22 O9K9W $	;M N NI H4&&tV444C!! 73!6!666C9$$//111V##"oodlHbIIG))'4FFByy**b00T]]75K5K0&*&6&6v~&N&N&.57F>2~66 I(,(8(8AR(S(S(08:TYY[[8HF#45 KK(9(9(;(;SAA	'3(+#';!*	  V##"kk'599G,,w//~~g..))VXsD$ABB IIdkk'&:&:DKK<T<TV]Vdfnoo	dnnk9-EFFFFsTz!V##99U++D4yyA~~#&(:GG
 '(KG %%di&6t&<H?  C fdwOOOr  c
                 @   |d S d|v r|                      |d          }
|
dk    r|                     |dd          }| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           |                     |dd	          }|                     | j        d         ||           t          |          d
|v rE| j        dz   |z   }|                      |d
          }|                     | j        d         ||           d S )Nr   errorr"  r!  rJ  r   r   zerr-msgerr_msgrk  )r   r  r0   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )r  httpCodereasonr   r  r  r  r  requestHeadersrequestBodyr   rk  feedbackmessages                 r  handle_errorszhtx.handle_errors  s;   4x %%h99F  ))(J
KK7S=4/44T_W5MtU]^^^44T_W5MtU]^^^,,Xy)LL44T_W5MwX`aaa#H---Xw}t+H##Hf55D001I4QYZZZtr  c                    |                                   |                     |          }|                     d||          \  }}ddi}|||d<   d}	|dk    r|d         |d<   |d	         rhd}
|                     d|          \  }
}|
d
n|
}
|
dk    r|d         |d<   n|d         |d<   |                     |                     ||                    }	n^|                     |                     ||                    }	n4|d         |d<   |                     |                     ||                    }	|                     |	dg           }| 	                    ||||          S )a  
        fetch the history of funding payments paid and received on self account
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-account-financial-records-via-multiple-fields-new   # linear swaps
        :see: https://huobiapi.github.io/docs/dm/v1/en/#query-financial-records-via-multiple-fields-new                          # coin-m futures
        :see: 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>`
        rm   r  z30,31N
start_daterB   r0   r   r   r$  r%  mar_acctri  r  r  )
r  r  r  r+  :contractPrivatePostLinearSwapApiV3SwapFinancialRecordExactr'  4contractPrivatePostSwapApiV3SwapFinancialRecordExact4contractPrivatePostApiV3ContractFinancialRecordExactry  parse_incomes)r  r  r  r  r	  r  r
  r  r(  r  r0  r  s               r  fetch_funding_historyzhtx.fetch_funding_history  s    	V$$ >>?TV\^dee
EG
 $)GL!"(,GJh 4r. "
%)%G%GH]_e%f%f"
F)3);WW*
++*0,GJ''*0*;GJ'ZZ[_[f[fgnpu[v[vww,  TTUYU`U`ahjoUpUpqq &tGHPPQUQ\Q\]dfkQlQlmmH~~h33!!$u===r  rn  c                 B   |t          | j        dz             |                                  |                     |          }|                     d||          \  }}d|i}|dk    r|d         r|d         |d<   n|d	         |d
<   d}|d         rd}	|                     d|          \  }	}|	dn|	}	|	dk    r*|                     |                     ||                    }n|	dk    r*|                     |                     ||                    }nt          | j        dz             |dk    r*| 
                    |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j        dz             |S )a$  
        set the level of leverage for a market
        :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   rl  rC   r   rj  r  r0   rQ  r   r$  r%  + setLeverage() not support self market typerB   )r   r0   r  r  r  r+  5contractPrivatePostLinearSwapApiV1SwapSwitchLeverRater'  :contractPrivatePostLinearSwapApiV1SwapCrossSwitchLeverRater$   /contractPrivatePostApiV1ContractSwitchLeverRate/contractPrivatePostSwapApiV1SwapSwitchLeverRate)
r  rn  r  r	  r  r
  r  r(  r  r0  s
             r  set_leveragezhtx.set_leverageB  s    >#DG.Y$YZZZV$$ >>}fV\]]
E(
 !!fY&7! &z 2GH'-d|GO$( 	\J!%!C!CMSY!Z!ZJ%/%7jJZ''UUVZVaVabikpVqVqrrw&&ZZ[_[f[fgnpu[v[vww"47-Z#Z[[[ X%%OOPTP[P[\cejPkPkllv%%OOPTP[P[\cejPkPkll"47-Z#Z[[[" r  c                 p   |                      |d          }|                     ||          }|                     |d          }|                     |d          }|                      |d          }|                     |dd          }|                     |          }	|||	||                     |          ||dS )NrQ  r7  r  r0   r  asset)r  r  rk  r  r  r0   r7  )r   r  r   r  r  r~  r  )
r  incomer  r"  r  r7  r  r0   r  rk  s
             r  parse_incomezhtx.parse_income  s     ##FO<<!!(F33!!&(33%%fd33	fd++'''BB
&&z22"Y//
 
 	
r  c                 j   |                      |                     |d                    }|d         }|                     |d          }|                     |d          }|                     |          }|                     |d          }|                     |d          }|                     |d          }	|	dk    rd	nd
}
|                     |d          }|                     |d          }|                     |d          }t          j        |                     |d          d          }|                     |d          }t          j        ||          }d }|d         rt          j        ||          }nt          j        ||          }d}t          j        ||          }|                     |d          }|                     |d          }|                     |d          }t          j        ||          }t          j        ||          }t          j        ||          }|                     i d|dd d|d| 	                    |          d|d|d| 	                    |          d|
d|d| 	                    |          d| 	                    |          d|d | 	                    |          d!d d"d d#|d$| 	                    |          | 	                    |          | 	                    |          | 	                    |          | 	                    |          d d d d d d d%
          S )&NrQ  r  r)  ro  	cost_openposition_marginr  r=  longshortprofit_unrealmargin_moderl  profit_raterh  
last_pricer   r$  r  liquidation_priceadjust_factorr  r0   	contracts
entryPrice
collateralr  unrealizedProfitrn  r   r0  notionalrQ  	lastPriceliquidationPriceinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior  r  hedgedlastUpdateTimestampr\  r^  )
r  r   r  rR  r   r,   rS  ro  safe_positionr  )r  positionr  r  r  ro  contractSizeStringr  r  rawSider  r  r0  rn  r   r  	faceValuer  intialMarginPercentager  r  adjustmentFactorr  r  r  s                            r  parse_positionzhtx.parse_position  s   @ !!$"2"28_"M"MNN!$$Xx88	v~>>!22<@@%%h<<
((3DEE""8[99!U**vv++HoFF%%h>>
##Hl;;'(8(8=(Q(QSXYY
$$X|<<	&y2DEE	( 	!))Y??HH))Y??H J!(!3M8!L!L%%h0@AA
++H6IJJ++HoFF&-&89I8&T&T##./JHUU():JGG!! #
H#
$#
 f#
 **955	#

 L#
 *#
 $++J77#
 D#
  0#
 ))(33#
 $++J77#
 *#
 ))(33#
 #
 #
   0!#
" T..}==##
$ (,'8'89O'P'P!%!2!23D!E!E+/+<+<=X+Y+Y,,[99#'!#7#
 #
 #
   	r  c           
      >   |                                   |                     |          }d}|+|                     |d          }|                     |          }d}|                     d|d          \  }}d}|                     d||d          \  }}d}|                     d||          \  }}|dk    rd}d}|dk    rO|dk    r|                     |          }n|dk    r|                     |          }nft          | j
        d	z             |dk    r|                     |          }n3|d
k    r|                     |          }nt          | j
        d	z             |                     |dg           }	|                     |d          }
g }t          dt!          |	                    D ]^}|	|         }|                     |          }|                    |                     ||
|                     |
          d                     _|                     |d|d          S )a*  
        fetch all open positions
        :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 `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   r   r$  r   r@   rC   r%  z. fetchPositions() not support self market typerB   r  r  r  r  r  F)r  r  r   r  r+  r  r  2contractPrivatePostLinearSwapApiV1SwapPositionInfo7contractPrivatePostLinearSwapApiV1SwapCrossPositionInfor$   r0   ,contractPrivatePostApiV1ContractPositionInfo,contractPrivatePostSwapApiV1SwapPositionInfor  r  r,  r-  r  rG  r'  r  filter_by_array_positions)r  r%  r	  r  r)  r0  r  r
  r  r  r  r0  r1  r  r  s                  r  fetch_positionszhtx.fetch_positions  si    	%%g..$$Wa00E[[''F
!??@PRXZabb
F99:JFTZ\dee
!??@PRXZ`aa
F!JhZ''RRSYZZw&&WWX^__"47-]#]^^^: X%%LLVTTv%%LLVTT"47-]#]^^^f x44%%h55	q#d))$$ 	 	AAwH((22FMM$++f& LL33/ /       --fhOOOr  c                 t   |                                   |                     |          }d}|                     d|          \  }}|dn|}|                     d||          \  }}i }|d         r|d         r|d         |d<   n|dk    rd|d	<   |d
         |d<   d}|d         rw|dk    r*|                     |                     ||                    }n|dk    r*|                     |                     ||                    }nt          | j        dz             |dk    r*| 	                    |                     ||                    }nG|dk    r*| 
                    |                     ||                    }nt          | j        dz             |                     |d          }	d}
|dk    r|	}
n|                     |	d          }
|                     |
dg          }|                     |
d          }d}|d         rG|d         r?t          dt          |                    D ] }||         }|d         |d
         k    r|} n!n|                     |d          }|                     |d          }|                     |                     ||                    }||d<   |                     |          |d<   |S )aa  
        fetch data on a single open contract trade position
        :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   r$  rC   r   rj  r  r	  r  r0   rQ  r   r%  z- fetchPosition() not support self market typerB   r  r  r   	positionsr  r  r  )r  r  r+  r  9contractPrivatePostLinearSwapApiV1SwapAccountPositionInfor'  >contractPrivatePostLinearSwapApiV1SwapCrossAccountPositionInfor$   r0   3contractPrivatePostApiV1ContractAccountPositionInfo3contractPrivatePostSwapApiV1SwapAccountPositionInfor  rL  r,  r-  r  r  r  )r  r  r	  r  r0  r
  r  r(  r  r  rl  omittedr  r  r1  r  r  r  s                     r  fetch_positionzhtx.fetch_positionx  s    	V$$
!??QWXX
F!+!3WW*
 >>PVX^__
E( 	4y 1 	4 &z 2GHW$$,2()'-d|GO$( B	\Z''YYZ^ZeZefmotZuZuvvw&&^^_c_j_jkrty_z_z{{"47-\#\]]]n X%%SSTXT_T_`ginToToppv%%SSTXT_T_`ginToTopp"47-Z#Z[[[L x00  GGoodA..G))Gk]33OOG[99	( 	5y 1 	51c)nn--  !!)VD\99$HE : y!44H%%h55	$$T[[7%C%CDD'{!\\)44zr  c                 R    ddddddddddddddd	}|                      |||          S )
Nr	  r!  r   creditr  r  exchangerebate)r	  etfztransact-feezfee-deductionr   r  liquidationrn  r  r   zwithdraw-feer  zother-typesr  r  )r  r  r   s      r  parse_ledger_entry_typezhtx.parse_ledger_entry_typel  sR    !"""  $!"%
 
  tT222r  c                    |                      |d          }|                      |d          }|                     ||          }|                     |d          }|                      |d          }|                     |          }|                      |d          }	|                     |d          }
|                     |
          }|                      |d          }||	|||||||
|d d d d |dS )	N
transactIdr  transactAmttransferTyper  transactTimerp  )r0   r  rl  referenceIdreferenceAccountr  r  r7  r  r  beforeafterr   r!  r  )r   r~  r   r  r  r  )r  itemr  r0   r  rk  r7  r  r  r  r  r  rl  s                r  parse_ledger_entryzhtx.parse_ledger_entry  s    dL11%%dJ77
&&z8<<!!$66''n==++L99$$T;77	%%dN;;	<<	**""455" '" 
 
 	
r  c                    |                                   d}|                     |dd          \  }}|r|                     d||||d          S |                     ddd|          }d|i}d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                    }	|                     |	dg           }
| 	                    |
|||          S )a  
        :see: https://huobiapi.github.io/docs/spot/v1/en/#get-account-history
        fetch the history of changes, actions done by the user or operations that altered balance of the user
        :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 entrys 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 [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger-structure>`
        Frv   r  i  r@   Nrp  r0   r  	startTimer  endTimer  )
r  rC  r(  rx  r  r)  spotPrivateGetV2AccountLedgerr'  r  parse_ledger)r  rk  r  r  r	  r  rp  r(  r  r  r  s              r  fetch_ledgerzhtx.fetch_ledger  sA    	88PZ[[& 	e44]D%QVX^`cddd11&$fMM		
 }}T**H"*4.GJ#(GK $GG229gvNN55dkk'66R6RSSB x44  x>>>r  c                     |                                   |                     |          }|                     |d          }|                     ||d          S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
        r  rQ  )r  0contractPublicGetLinearSwapApiV1SwapAdjustfactorry  parse_leverage_tiers)r  r%  r	  r  r  s        r  fetch_leverage_tierszhtx.fetch_leverage_tiers  sV     	HHPP< ~~h//((wHHHr  c                    |                                   i }|?|                     |          }|d         st          | j        dz             |d         |d<   |                     |                     ||                    }|                     |d          }|                     ||gd          }|                     ||          S )a}  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage tiers structure <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
        Nr   zA fetchMarketLeverageTiers() symbol supports contract markets onlyr0   rQ  r  )r  r  r   r0   r  r'  r  r  )r  r  r	  r(  r  r  r  tierss           r  fetch_market_leverage_tierszhtx.fetch_market_leverage_tiers  s     	[[((F*% p +n!nooo'-d|GO$HHU\^dIeIeff< x00))$/JJuf---r  c                    i }t          dt          |                    D ]}||         }|                     |dg           }g }|                     |d          }	|                     ||          }
|                     |
          }|                     ||          r?t          dt          |                    D ]}||         }|                     |d          }|                     |dg           }t          dt          |                    D ]}||         }|                     |d          }|                    |                     |d          |                     |	          | 	                    |d          | 	                    |d	          | 
                    t          j        ||                    | 
                    |          |d
           Ɛ|||<   |S )Nr   rD  trade_partitionrl  laddersr  laddermin_sizemax_size)tierr  minNotionalmaxNotionalmaintenanceMarginRatemaxLeverager  )r,  r-  r  r   r  r'  rG  r  r~  r   r  r,   ro  )r  r  r%  marketIdKeyr0  r1  r  rD  r  r  r0   r  r;  objrn  r  kbracketadjustFactors                      r  r  zhtx.parse_leverage_tiersK  s   q#h--(( 	' 	'AA;D??444DE''.?@@H!!$44B%%b))F}}VW-- 'q#d)),,  Aq'C#//\BBH"ooc9bAAG"1c'll33  ")!*'+'7'7'Q'Q$($5$5gx$H$H(,(?(?(I(I+/+;+;GZ+P+P+/+;+;GZ+P+P595F5FwGYZfhpGqGq5r5r+/+<+<X+F+F$+& &     "'vr  r   c                 Z   |dk    r)|dk    r#|dk    r|dk    rt          | j        dz             |                                  dddd	d
}|                     |          }|                     |ddd          }||         |d}	|||	d<   d}
|d         rT|                     |d         d          |	d<   |d         |	d<   |                     |                     |	|                    }
n|d         rEd|	d<   |d         |	d<   |d         |	d<   |                     |                     |	|                    }
n4|d         |	d<   | 	                    |                     |	|                    }
| 
                    |
d          }|                     |d          }|                     ||||          S )u  
        Retrieves the open interest history of a currency
        :see: https://huobiapi.github.io/docs/dm/v1/en/#query-information-on-open-interest
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-information-on-open-interest
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-information-on-open-interest
        :param str symbol: Unified CCXT market symbol
        :param str timeframe: '1h', '4h', '12h', or '1d'
        :param int [since]: Not used by huobi api, but response parsed by CCXT
        :param int [limit]: Default：48，Data Range [1,200]
        :param dict [params]: Exchange specific parameters
        :param int [params.amount_type]: *required* Open interest unit. 1-cont，2-cryptocurrency
        :param int [params.pair]: eg BTC-USDT *Only for USDT-M*
        :returns dict: an array of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
        r   r   12hr   zJ fetchOpenInterestHistory cannot only use the 1h, 4h, 12h and 1d timeframer   r   12hourr   )r   r   r  r   amount_type
amountTyper`  )rB  r   Nr  rC   r  r  rh  r  r   rB   r0   rQ  r  r  )r   r0   r  r  r  r   -contractPublicGetApiV1ContractHisOpenInterestr'  3contractPublicGetLinearSwapApiV1SwapHisOpenInterest-contractPublicGetSwapApiV1SwapHisOpenInterestr  ry  parse_open_interests)r  r  r^  r  r  r	  r   r  r!  r(  r  r  r  s                r  fetch_open_interest_historyzhtx.fetch_open_interest_historyh  s    d!2!2yE7I7Ii[_N_N_TW'ssttt	
 

 V$$((aPP
 +%
 
 #GFO( 	h'+'7'7v'X'XGO$ &x 0GHII$++V]_eJfJfggHHH 		h'-GO$'-d|GO$'-d|GO$OOPTP[P[\cekPlPlmmHH'-d|GO$II$++V]_eJfJfggHz x00~~dF++((vueDDDr  c                 0   |                                   |                     |          }|d         st          | j        dz             |d         rt	          | j        dz             d|d         i}d}|d         rT|                     |d	         d
          |d
<   |d         |d<   |                     |                     ||                    }n`|d         r/d|d
<   |                     |                     ||                    }n)| 	                    |                     ||                    }| 
                    |dg           }|                     |d         |          }|                     |d          }||d<   |                     |          |d<   |S )aM  
        Retrieves the open interest of a currency
        :see: https://huobiapi.github.io/docs/dm/v1/en/#get-contract-open-interest-information
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-swap-open-interest-information
        :see: 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 onlyrD   z> fetchOpenInterest() does not currently support option marketsrQ  r0   NrC   r  r  rh  r  r   rB   r  r   r  r  r  )r  r  r   r0   r$   r   *contractPublicGetApiV1ContractOpenInterestr'  0contractPublicGetLinearSwapApiV1SwapOpenInterest*contractPublicGetSwapApiV1SwapOpenInterestr  parse_open_interestr  r  )	r  r  r	  r  r(  r  r  openInterestr  s	            r  fetch_open_interestzhtx.fetch_open_interest  s    	V$$j! 	^TW'\\]]]( 	ktw)iijjjVD\
 ( 	e'+'7'7v'X'XGO$ &x 0GHFFt{{SZ\bGcGcddHHH 	e'-GO$LLT[[Y`bhMiMijjHH FFt{{SZ\bGcGcddH| x44//Q@@%%h55	$-[!#'<<	#:#:Z r  c                    |                      |d          }|                     |d          }|                     |d          }|                     |                     |d          ||||||                     |          |d|          S )Nr  r)  valuer  )r  r  r  openInterestAmountopenInterestValuer  r  r  )r  r   safe_open_interestr   r  )r  rn  r  r  r7  r/  s         r  r+  zhtx.parse_open_interest<  s    j %%h55	!!(H55  733&&&&vx88  "(!&"Y//	(
 	(
 	 	 		r  c                 z   |                                   |                     |          }|                     |          }|d         |                     ||          |d         d}|                     |                     ||                    }|                     ||          }	|                     |	||d          S )ac  
        create a loan to borrow margin
        :see: https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-isolated
        :see: 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>`
        r0   )r  r7  r  r7  r  )r  r  r  r  privatePostMarginOrdersr'  parse_margin_loan)
r  r  rk  r7  r	  r  r  r(  r  r  s
             r  borrow_isolated_marginzhtx.borrow_isolated_margin  s     	==&&V$$ 00v>>Tl
 

 //GV0L0LMM ,,Xx@@{{;)
 )
   	r  c                 @   |                                   |                     |          }|d         |                     ||          d}|                     |                     ||                    }|                     ||          }|                     |d|i          S )a  
        create a loan to borrow margin
        :see: https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-isolated
        :see: 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>`
        r0   r%  r7  )r  r  r  privatePostCrossMarginOrdersr'  r6  )r  rk  r7  r	  r  r(  r  r  s           r  borrow_cross_marginzhtx.borrow_cross_margin  s     	==&& 00v>>
 
 44T[[&5Q5QRR ,,Xx@@{{;f)
   	r  c                    |                                   |                     |          }|                     dd||          }|d         |                     ||          |d}|                     |                     ||                    }|                     |dg           }	|                     |	d          }
|                     |
|          }|                     |||d          S )a  
        repay borrowed margin and interest
        :see: 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 str symbol: unified market symbol
        :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%  r0   r  r7  rp  Datar   r4  r  r  rx  r  v2PrivatePostAccountRepaymentr'  r  r6  )r  r  rk  r7  r	  r  rp  r(  r  r  loanr  s               r  repay_isolated_marginzhtx.repay_isolated_margin  s     	==&&11&*ffUU	 00v>>"
 

 55dkk'66R6RSS x44tQ'',,T8<<{{;)
 )
   	r  c                    |                                   |                     |          }|                     ddd|          }|d         |                     ||          |d}|                     |                     ||                    }|                     |dg           }|                     |d          }	|                     |	|          }
|                     |
d|i          S )	a  
        repay borrowed margin and interest
        :see: 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>`
        r@   r$  Nr0   r<  r=  r   r7  r>  )r  rk  r7  r	  r  rp  r(  r  r  r@  r  s              r  repay_cross_marginzhtx.repay_cross_margin  s     	==&&11&'4PP	 00v>>"
 

 55dkk'66R6RSS x44tQ'',,T8<<{{;f)
   	r  c                     |                      |d          }|                     |dd          |                     d |          d d ||                     |          |dS )N	repayTimerepayIdr  )r0   r  r7  r  r  r  r  )r  r  r~  r  )r  r  r  r  s       r  r6  zhtx.parse_margin_loan  sk    , %%dK88	$$T9f==//h??"Y//
 
 	
r  c                    |t          | j        dz             |                     |dd          }|                     |ddg          }|                     |          }i }|d         r|d         |d<   n|d         |d	<   |||d
<   |||d<   |||d<   d}|d         r\|d         r*|                     |                     ||                    }nS|                     |                     ||                    }n)|                     |                     ||                    }| 	                    |d          }	| 	                    |	d          }
| 
                    |
|          }|                     |d          S )u"  
        Fetches historical settlement records
        :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 argumentrD  tillrC   rh  r  r0   rQ  start_atr#  end_atrB   r   r  settlement_recordr  )r   r0   r  rL  r  5contractPublicGetLinearSwapApiV1SwapSettlementRecordsr'  /contractPublicGetSwapApiV1SwapSettlementRecords/contractPublicGetApiV1ContractSettlementRecordsr  parse_settlementsr9  )r  r  r  r  r	  rD  r  r(  r  r  settlementRecordsettlementss               r  fetch_settlement_historyzhtx.fetch_settlement_history)  s    >#DG.d$deee##FGV<<6GV#455V$$( 	4 &x 0GH'-d|GO$"'GJ#(GK  %GH&> 	jh nUUVZVaVabikqVrVrssOOPTP[P[\cekPlPlmmKKDKKX_agLhLhiiHj x00??41DEE,,-=vFF||K555r  codesc                     |                                   |                     |          }|                     |d          }|                     ||d          S )a  
        fetch deposit and withdraw fees
        :see: https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-currencies-v2
        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fees structures <https://docs.ccxt.com/#/?id=fee-structure>`
        r  r  )r  r  ry  parse_deposit_withdraw_fees)r  rS  r	  r  r  s        r  fetch_deposit_withdraw_feeszhtx.fetch_deposit_withdraw_fees  sW     	::6BBJ ~~h////eZHHHr  c                     |                      |dg           }|                     |          }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |          }	d }
d }|dk    r|                     |d          }
|
dd}n|                     |d	          }
|
d
d}|d d dd|d         |	<   |                     ||          }|S )Nr|  r   r  withdrawFeeTypefixedr  F)r!  r   transactFeeRateWithdrawT)r   r  r
  )r  deposit_withdraw_feer,  r-  r   r  r   $assign_default_deposit_withdraw_fees)r  r!  r  r|  r0  r;  r  r  rX  r  withdrawFeewithdrawResults               r  parse_deposit_withdraw_feezhtx.parse_deposit_withdraw_fee  sG   @ h33**3//q#f++&& 	Q 	QAJ((W==I"..z;LMMO11)<<KK!N'))"..z;PQQ&"'" "
 #..z;TUU&"&" "
 +"& / /F:{+ >>vxPPFFr  c                    g }t          dt          |                    D ]}||         }|                     |d          }||                     |d          }||                     |          d}t          dt          |                    D ]I}	||	         }
|                     |
|          }|                    |                     ||                     J|                    |                     ||         |                     |S )Nr   rD  settlement_timer  )r,  r-  r  r  r  parse_settlementrG  r'  )r  rQ  r  r0  r1  
settlementrD  r  timestampDetailsr;  r  parsedSettlements               r  rO  zhtx.parse_settlements  s!   J q#k**++ 	M 	MA$QJ??:v66D --j:KLL	!* $Y 7 7$ $  q#d)),, S SA7D'+'<'<T6'J'J$MM$++.>@P"Q"QRRRRS
 d33KNFKKLLLLr  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||                     |          dS )Nra  rQ  settlement_price)r  r  rl  r  r  )r  r   r  r   r  )r  rc  r  r  r"  s        r  rb  zhtx.parse_settlement-   sz    0 %%j2CDD	##J@@&&x88%%j2DEE"Y//
 
 	
r  c                    |                                   |                     |          }|                     |dd          }d|i}|||d<   |                     d||          \  }}d}|d         rg|d         |d<   |d	         r*|                     |                     ||                    }n|                     |                     ||                    }n`|d
         r5|d         |d<   |                     |                     ||                    }n#t          | j	        dz   |d         z   dz             | 
                    |dg           }	|                     |	|||          S )aH  
        retrieves the public liquidations of a trading pair
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-liquidation-orders-new
        :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-liquidation-orders-new
        :see: 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"  rB   r0   r   r   rC   r  z& fetchLiquidations() does not support r  r  r  )r  r  r  r)  5contractPublicGetLinearSwapApiV3SwapLiquidationOrdersr'  /contractPublicGetSwapApiV3SwapLiquidationOrders/contractPublicGetApiV3ContractLiquidationOrdersr$   r0   ry  parse_liquidations)
r  r  r  r  r	  r  	tradeTyper(  r  r  s
             r  fetch_liquidationszhtx.fetch_liquidationsO   s    	V$$%%flA>>	)
 $)GL!22:wOO&> 
	p"(,GJh nUUVZVaVabikqVrVrssOOPTP[P[\cekPlPlmmH 	p &tGHKKDKKX_agLhLhiiHHtw)QQTZ[aTbbennooo0 ~~h33&&tVUEBBBr  c                    |                      |d          }|                     |d          }|                     ||                     ||          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          ||                     |          d	          S )	NrQ  r  r)  ro  rl  r7  r  )	r  r  r  ro  rl  	baseValue
quoteValuer  r  )r   r  safe_liquidationr  r   r  )r  r  r  r"  r  s        r  parse_liquidationzhtx.parse_liquidation   s    " ##KAA%%k<@@	$$&&x88))+x@@ ,,V^DD%%k7;;))+x@@**;8HII"Y//
&
 
&
 
 
 
	r  r  c                    |                                   |rdnd}d}||                     |          }d}|                     d|d          \  }}d|i}d}||d         rt          | j        dz             |d	k    rN|t          | j        d
z             |d         |d<   |                     |                     ||                    }n.d|d<   |                     |                     ||                    }|S )a  
        set hedged to True or False
        :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-switch-position-mode
        :see: 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   r$  position_moder   z4 setPositionMode can only be used for linear marketsr%  zD setPositionMode requires a symbol argument for isolated margin moder0   r  r	  )	r  r  r+  r   r0   r   8contractPrivatePostLinearSwapApiV1SwapSwitchPositionModer'  =contractPrivatePostLinearSwapApiV1SwapCrossSwitchPositionMode)	r  r  r  r	  posModer  r0  r(  r  s	            r  set_position_modezhtx.set_position_mode   s4    	!':++][[((F
!??@QSY[bcc
FW
 VI%6TW']]^^^##~'2x(xyyy(.tG$%TTUYU`U`ahjpUqUqrrHH )/G$%YYZ^ZeZefmouZvZvwwH r  )N)NN)__name__
__module____qualname__r  r  r  r
   r   r#  r  r*  r   r2  r.  r   r5  rA  r   rM  rH  r  r   r  r  r   r  r  r  r	   r   r  r   r  r  r  r1  r<  rD  r@  re  r   ri  rn  rx  r   r  r  r  r   r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r?  r   r   r   rC  rX  rx  r>  r   r  r  r  r  r   r  r  r  r  r   r  r  r  r  r   r#  r   r   r;  r9  rM  r]  ra  rg  ro  rr  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r&  r-  r+  r7  r:  rA  rC  r6  rR  rV  r_  rO  rb  rn  rs  boolr{  __classcell__)r  s   @r  r.   r.       s       | | | | ||% #% O
 O
 O
 O
b !# ; ; ; ;4
 
V 
?R 
 
 
 
( 57 5 5 5;N 5 5 5 5@ 7;2  G     :< P PS P P P P. :>b 
 
3 
 
 
 
4x x x $&  $v,    4 HJ L L L L\  3            D] ]6 ]V ] ] ] ]~ 02 H H3 Hf H H H HT 04B fH fHW fH7 fH fH fH fHP 48 a5 a5 a5 a5 a5 a5F
 
f 
 
 
 
  :>b Nr Nrs Nr3 NrY Nr Nr Nr Nr`A A A5 A A A AF 9=4^bkm N NS N# NS NX[ N N N N& >BPTcgpr G G# Gs G# G]` G G G G -1tRV_a W? W?c W? W?C W? W? W? W?r 6:UW FY FY3 FYs FY# FY\`af\g FY FY FY FYP
 
 
4 
 
 
 
, 26DW[df }H }H# }Hc }HQT }Hkoptku }H }H }H }H~ %' ) )4= ) ) ) )(
 
 
& 9=TRT 6 6 6 60 ') @ @Z @ @ @ @DA A A A A AQ Q Q Q Q Q $& n n( n n n n`	 26b ' 'c '3 ' ' ' 'B
 
 
 AESWfjsu A= A=# A=S A=`c A= A= A= A=F /3TXac Y Y Y3 Yc Y Y Y Y 6:[_hj r rs r# rUX r r r r 37TX\eg [? [?C [?s [?RU [? [? [? [?z :>D_cln ^ ^3 ^c ^Y\ ^ ^ ^ ^ *.Dt\^ H H3 Hc H Hcghmcn H H H HB 154VZce S S# SS SPS Sjnotju S S S S@ /3TXac Y? Y? Y?3 Y?c Y?hlmrhs Y? Y? Y? Y?v: : :*p p p5 p p p pd RT N N N5 N N N N  x|  NR  im  vx L LC Ly LPY Lch Lqt L  }B L L L L* tx  AC f, f, f,9 f,I f,_d f,mp f, f, f, f,P x|  EG O, O,C O,y O,PY O,ch O,qt O, O, O, O,b gksu X0 X03 X0i X0y X0RW X0`c X0 X0 X0 X0t @B p1 p1D$6 p1 p1 p1 p1d 37r y ys yC y y y yv 04B Q Q Q Q Q Qf /32 o o o o o ob
 
h 
 
 
 
4 DF 0 0s 0 0 0 0< 79 5 5# 5 5 5 5 8<VX  S    @ *.Dt\^ 3Q 3Q3 3Qc 3Q 3Qcghsct 3Q 3Q 3Q 3Qj -1tRV_a 1Q 1Qc 1Q 1QC 1Qfjkvfw 1Q 1Q 1Q 1QfZ
 Z
x Z
; Z
 Z
 Z
 Z
x: : :. ?C2 3: 3:S 3:% 3: 3: 3: 3:j
 
 
 
 
 
. [] P7 P7S P7% P7c P7c P7an P7 P7 P7 P7d 24 ) ) ) )V)
 )
v )
 )
 )
 )
V 8<$]ajl FY FY FYC FYWZ FY FY FY FYP'
 '
6 '
 '
 '
 '
R 68 #7 #7 #7 #7 #7 #7J 6:" ,? ,?7 ,? ,? ,? ,?\ 15DW[jnwy 7Q 7Q# 7Qc 7QQT 7Qdg 7Q 7Q 7Q 7Qr:
 :
& :
 :
 :
 :
x &eBSW jP jP jP jPX  . 37TX\eg P> P>C P>s P>RU P> P> P> P>d 9=R A AS A# A A A AF
 
6 
 
 
 
8X Xv X X X Xt 26b {P {Pw {P {P {P {Pz 24 r rS r r r rh3 3 3&(
 (
 (
 (
 (
 (
T (,$TZ\ G? G? G?C G?s G? G? G? G?R 7;2 'I 'IG 'I 'I 'I 'IR ?A .. ..# .. .. .. ..` g    : BFTXgktv nE nE# nEc nEad nE nE nE nE` 79 b b# b b b bHA AF A A A AF TV  S  U    B DF   U    < LN $ $C $s $ $ $ $L <> " "s " " " "H
 
 
 
 
 
B 6:[_hj [6 [6s [6# [6UX [6 [6 [6 [6z <@ /I /I /I /I /I /Ib= = = = = =~5 5 5n 
  
  
D <@d[] ;C ;C ;CS ;C ;C ;C ;C ;Cz V    > =A 8 8 8c 8 8 8 8 8 8 8 8r  r.   )3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   typingr   ccxt.base.errorsr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   ccxt.base.decimal_to_precisionr*   r+   ccxt.base.preciser,   r.    r  r  <module>r     s   ( ' ' ' ' ' ) ) ) ) ) )  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c  c       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) , , , , , , . . . . . . 1 1 1 1 1 1 * * * * * * + + + + + + 3 3 3 3 3 3 4 4 4 4 4 4 % % % % % %CC CC CC CC CC(K CC CC CC CC CCr  