
    E#ip                       S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$  S SK%J&r&  S SK'J(r(  S SK'J)r)  S SK'J*r*  S S	K'J+r+  S S
K'J,r,  S SK'J-r-  S SK'J.r.  S SK'J/r/  S SK'J0r0  S SK'J1r1  S SK'J2r2  S SK'J3r3  S SK'J4r4  S SK'J5r5  S SK'J6r6  S SK'J7r7  S SK8J9r9  S SK8J:r:  S SK;J<r<   " S S\\5      r=g)    )Exchange)ImplicitAPIN)AccountAnyBalancesBorrowInterest
CurrenciesCurrencyDepositAddressIntIsolatedBorrowRateIsolatedBorrowRatesLedgerEntryLeverageTierLeverageTiersMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountNotEnabled)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)OperationFailed)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)RequestTimeout)TRUNCATE)	TICK_SIZE)Precisec                      ^  \ rS rSrS\4U 4S jjr0 4S jr0 4S\4S jjrSS\	S\
S\4S	 jjr0 4S
\S\4S jjrS0 4S\4S jjr0 4S\4S jjrS0 4S
\4S jjrS r0 4S\\
   4S jjr0 4S\S\4S jjrS\4S jrSS\	S\
S\4S jjr0 4S
\S\4S jjrS0 4S\S\4S jjrS0 4S\4S jjrSS\
4S jjrS0 4S
\S\S\ 4S jjr!SS \	S\
S\"4S! jjr#SSS0 4S\S
\S"\S\4S# jjr$SSS0 4S\S
\S"\S\4S$ jjr%SSS0 4S
\S"\S\4S% jjr&SS&0 4S
\S"\S\S\\"   4S' jjr'SS\
S\(4S( jjr)S)SS0 4S
\S*\S"\S\S\\(   4
S+ jjr*0 4S\\+   4S, jjr,S- r-SS0 4S\S.\S
\4S/ jjr.0 4S\/4S0 jjr0SS1\S2\4U 4S3 jjjr1SS4\S2\4U 4S5 jjjr20 4S\34S6 jjr4S0 4S\S
\4S7 jjr5S8 r6SSS0 4S
\S"\S\4S9 jjr7SSS0 4S
\S"\S\4S: jjr8SSS0 4S
\S"\S\4S; jjr9SSS0 4S
\S"\S\4S< jjr:SSS0 4S
\S"\S\4S= jjr;SSS0 4S
\S"\S\S\\<   4S> jjr=SSS0 4S
\S"\S\S\\<   4S? jjr>SSS0 4S
\S"\S\S\\<   4S@ jjr?SA\4SB jr@SSC\	S\
S\<4SD jjrA0 4S
\SE\B4SF jjrCSSS0 4S
\S\DSG\ESH\BSI\FSJ\FSK\FS\<4SL jjrGS0 4S
\S\DSG\ESH\BSI\F4
SM jjrHS0 4S
\S\DSG\ESH\BSI\F4
SN jjrIS0 4S
\S\DSG\ESH\BSI\F4
SO jjrJ0 4SP\\K   4SQ jjrLS0 4S\S
\4SR jjrMS0 4SS\\   S
\4ST jjrNSU rOS0 4S
\4SV jjrP0 4SW\4SX jjrQSSY\R4SZ jjrS0 4S[\S\\T   4S\ jjrU0 4S[\S\T4S] jjrVSS0 4S[\4S^ jjrWSSS0 4S[\S"\S\S\\X   4S_ jjrYSSS0 4S[\S"\S\S\\X   4S` jjrZSSa\	SY\RS\X4Sb jjr[SA\4Sc jr\S0 4S[\SH\BSd\Se\S\X4
Sf jjr]SSg\	SY\RS\^4Sh jjr_0 4S[\SH\BSi\Sj\S\^4
Sk jjr`0 4S\a4Sl jjrbSSm\	S\
S\c4Sn jjrdSSS0 4S
\S"\S\4So jjreSS\
S\f4Sp jjrgSq rh0 4S
\S\f4Sr jjriS0 4S\S\j4Ss jjrkSSSS0 4S[\S
\S"\S\S\\l   4
St jjrmSSm\	S\
S\l4Su jjrnSv roSwSx0 SS4Sy jrpSz\qS{\S|\S}\S~\	S\4S jrrSSS0 4S
\S"\S\4S jjrsS0 4S\qS
\4S jjrtSS\
4S jjruSS\	S\
4S jjrvS0 4S\S\\w   4S jjrx0 4S
\4S jjryS rzSS\	SY\RS\{4S jjr|SSS0 4S[\S"\S\S\\{   4S jjr}S0 4S\S\~4S jjrSS\
S\\   4S jjrSSS0 4S
\S"\S\4S jjrS0 4S\4S jjr0 4S
\4S jjrSS\
4S jjr0 4S
\S[\SH\B4S jjr0 4S[\SH\B4S jjr0 4S
\S[\4S jjr0 4S[\4S jjrSSY\R4S jjrSSS0 4S
\S"\S\4S jjrS0 4S\4S jjrSSY\R4S jjrS rS rSS0 4S
\S"\S\4S jjrSS\
4S jjrS0 4S
\SG\ES\<4S jjrS0 4S\S
\4S jjrSrU =r$ )htx    returnc                    > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	U R                  S
   _SS_SS_SS_SS_S0 SS _SS_SS_SS_SS_SS _SS _SS_SS_SS_SS_SS_SS_S S!_S"S_S#S _S$S_0 S%S!_S&S!_S'S_S(S_S)S!_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_S2S_S3S _S4S_S5S _E0 S6S _S7S _S8S _S9S_S:S!_S;S!_S<S_S=S _S>S_S?S _S@S_SAS_SBSC_SDS_SES_SFS_SGS_E0 SHS_SIS_SJS!_SKS_SLS _SMS_SNS_SOS _SPS!_SQS_SRS_SSS!_STSC_SUS_SVS_SWS!_SXS_E0 SYS_SZS_S[S_S\S_S]S _S^S_S_S_S`S_SaS _SbS_ScS_SdS_SeSC_SfS_SgS!_ShS!_SiS_E0 SjS_SkS_SlS_SmS_SnS_SoS_SpS_SqS!_SrS_SsS _StS _SuS _SvS _SwS_SxS _SyS_SzS _ES SSSS!SS SSS{.	E_S|S}S~SSSSSSSSS.
_SSSSSSSS.SSS.S.S.SSSSSSSS.SSSS./ SQSS._SSSSS.00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSSSSS.E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSS.ES.SSSSSSS.00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSS.E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSS.ES.SSSS00SSS00SSS00S.SSS00SSS00S.S.0S0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSGS .E00 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GS	S_GS
S_SS_GSS_GSS_GSS_GSS_GSS_GSS_0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GS S_GS!S_ESSSSSSSSSSSSGS".E0 GS#S_GS$S_GS%S_GS&S_GS'S_GS(S_GS)S_GS*S_GS+S_GS,S_GS-S_GS.S_GS/S_GS0S_GS1S_GS2S_GS3S_0 GS4S_GS5S_GS6S_GS7S_GS8S_GS9S_GS:S_GS;S_GS<S_GS=S_GS>S_GS?S_GS@S_GSAS_GSBS_GSCS_GSDS_ESSSSSSGSE.ES.GSF.S0 GSGS_GSHS_GSIS_GSJS_GSKS_GSLS_GSMS_GSNS_GSOS_GSPS_SS_GSQS_SS_GSRS_GSSS_GSTS_GSUS_0 GSVS_GSWS_GSXS_GSYS_GSZS_GS[S_GS\S_GS]S_GS^S_GS_S_GS`S_GSaS_GSbS_GScS_GSdS_GSeS_GSfS_E0 GSgS_GShS_GSiS_GSjS_GSkS_GSlS_GSmS_GSnS_GSoS_GSpS_GSqS_GSrS_GSsS_GStS_GSuS_GSvS_GSwS_E0 GSxS_GSyS_GSzS_GS{S_GS|S_GS}S_GS~S_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_ESSSSSSSSSSSSSSGS.E0SSSSSSSSSSSSGS.0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSGS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSGS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GS S_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GS	S_GS
S_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GS S_GS!S_GS"S_GS#S_GS$S_E0 GS%S_GS&S_GS'S_GS(S_GS)S_GS*S_GS+S_GS,S_GS-S_GS.S_GS/S_GS0S_GS1S_GS2S_GS3S_GS4S_GS5S_E0 GS6GS_GS7GS_GS8S_GS9S_GS:S_GS;S_GS<S_GS=S_GS>S_GS?S_GS@S_GSAS_GSBS_GSCS_GSDS_GSES_GSFS_E0 GSGS_GSHS_GSIS_GSJS_GSKS_GSLS_GSMS_GSNS_GSOS_GSPS_GSQS_GSRS_GSSS_GSTS_GSUS_GSVS_GSWS_E0 GSXS_GSYS_GSZS_GS[S_GS\S_GS]S_GS^S_GS_S_GS`S_GSaS_GSbS_GScS_GSdS_GSeS_GSfS_GSgS_GShS_ESSSSSSSSSSSSSGSi.ES.GSF.GSj._GSkGSlSS!SU R                  GSm5      U R                  GSm5      GSn.0_GSo[        [        [        GSp.0 GSq[        _GSr[        _GSs[        _GSt[        _GSu[        _GSv[        _GSw[        _GSx[        _GSy[        _GSz[        _GS{[        _GS|[        _GS}[        _GS~[        _GS[        _GS[        _GS[        _0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[         _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[         _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS["        _GS[        _E[        [        [        [        [        [        [        ["        GS.EGS._GS[$        _GS0 GSS!_SUGSSSSGS.0_GSGS_GSS!_SYGSS0_GSGSS!0_GSS_GSGS_GSGS_GSGSGSGSGS._GS0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GS GS _GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GS	GS	_GS
GS
_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GS GS _GS!GS!_GS"GS"_GS#GS#_E0 GS$GS$_GS%GS%_GS&GS&_GS'GS'_GS(GS(_GS)GS)_GS*GS*_GS+GS+_GS,GS,_GS-GS-_GS.GS._GS/GS/_GS0GS0_GS1GS1_GS2GS2_GS3GS3_GS4GS4_E0 GS5GS5_GS6GS6_GS7GS7_GS8GS8_GS9GS9_GS:GS:_GS;GS;_GS<GS=_GS>GS>_GS?GS@_GSAGSB_GSCGSC_GSDGSD_GSEGSE_GSFGSF_GSGGSG_GSHGSH_E0 GSIGSI_GSJGSJ_GSKGSK_GSLGSL_GSMGSM_GSNGSO_GSPGSP_GSQGSQ_GSRGSR_GSSGSS_GSTGST_GSUGSU_GSVGSV_GSWGSW_GSXGSX_GSYGSY_GSZGSZ_E0 GS[GS[_GS\GS\_GS]GS]_GS^GS^_GS_GS__GS`GS`_GSaGSa_GSbGSb_GScGSc_GSdGSd_GSeGSf_GSgGSg_GShGSh_GSiGSi_GSjGSj_GSkGSk_GSlGSl_EGSmGSnGSo.E_GSpGSq_GSrS_GSsGSt_GSuSGSv0_GSwSSGSxGSy._GSzSSGS{GS|GS}GS~GSGSGSGSGS.
_SSGS.SSSSSSGS.0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS0EGS.GS.E_GSGSGSGSGSGSGSGSGSGS.	SSSSS S!S!S SSSS!GS.S!S!S!SSSSGS.GSS0S!GSGSGSS!GS.S!S!S!S!GS.S!SS!GSS!GS.S!SS!GSGSGSS!GS.S!SS!GSGSGSGSS!GS.GSGS0GS.	SSSSSGS.GSGS0GSS0SS!S!SGS.SS!S!SGSGS.SS!S!GSSGSGSGS.GSGS0GS.GSGS0GSGS0GS.GSGS0GSGS0GS.GS.GS.E5      $ (  Nidr9   nameHTX	countriesCN	rateLimitd   	userAgent	chrome100	certifiedTversionv1hostnamezapi.huobi.proprohasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscloseAllPositionsFclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingPercentOrdercreateTriggerOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLastPricesfetchLedgerfetchLedgerEntryfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginAdjustmentHistoryfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelist)	reduceMarginrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModesetPositionModesignIntransferwithdraw
timeframes1min5min15min30min60min4hour1day1week1mon1year)
1m5m15m30m1h4h1d1w1M1yurlszchttps://user-images.githubusercontent.com/1294454/76137448-22748a80-604e-11ea-8069-6e389271911d.jpgzapi.hbdm.comzstatus.huobigroup.comzstatus-dm.huobigroup.comz!status-linear-swap.huobigroup.com)inverselinearzstatus-swap.huobigroup.com)rM   rP   rO   )contractrM   statuszhttps://{hostname})r   r   rM   publicprivatev2Public	v2Privatezhttps://www.huobi.comz;https://www.htx.com.vc/invite/en-us/1h?invite_code=6rmm2223g333333?)urldiscount)z+https://huobiapi.github.io/docs/spot/v1/en/z)https://huobiapi.github.io/docs/dm/v1/en/z9https://huobiapi.github.io/docs/coin_margined_swap/v1/en/z0https://huobiapi.github.io/docs/usdt_swap/v1/en/z.https://www.huobi.com/en-us/opend/newApiPages/z https://www.huobi.com/about/fee/)logo	hostnamesapiwwwreferraldocfeesr   get   )zreference/currencieszmarket-statuszaccount/ledgerzaccount/withdraw/quotazaccount/withdraw/addresszaccount/deposit/addresszaccount/repayment   zreference/transact-fee-ratezaccount/asset-valuationg?zpoint/accountzsub-user/user-listzsub-user/user-statezsub-user/account-listzsub-user/deposit-addresszsub-user/query-depositzuser/api-keyzuser/uidzalgo-orders/openingzalgo-orders/history)zalgo-orders/specificz
c2c/offers	c2c/offerzc2c/transactionsc2c/repaymentzc2c/accountzetp/referencezetp/transactionszetp/transactionzetp/rebalancez	etp/limitzaccount/transferzpoint/transferzsub-user/managementzsub-user/creationzsub-user/tradable-marketzsub-user/transferabilityzsub-user/api-key-generationzsub-user/api-key-modificationzsub-user/api-key-deletionzsub-user/deduct-modezalgo-orderszalgo-orders/cancel-all-afterzalgo-orders/cancellationr   zc2c/cancellationzc2c/cancel-all
   2   )r   zc2c/transferzetp/creationzetp/redemptionzetp/{transactId}/cancelzetp/batch-cancel)r   post)zcommon/symbolszcommon/currencyszcommon/timestampzcommon/exchangezsettings/currencyszaccount/accountszaccount/accounts/{id}/balancezaccount/accounts/{sub-uid}zaccount/history   zcross-margin/loan-infozmargin/loan-infozfee/fee-rate/getzorder/openOrdersg?zorder/orderszorder/orders/{id}zorder/orders/{id}/matchresultszorder/orders/getClientOrderzorder/historyzorder/matchresultszquery/deposit-withdrawzmargin/loan-orderszmargin/accounts/balance)zcross-margin/loan-orderszcross-margin/accounts/balancezpoints/actionszpoints/orderszsubuser/aggregate-balancezstable-coin/exchange_ratezstable-coin/quotezfutures/transferzorder/batch-orderszorder/orders/placez$order/orders/submitCancelClientOrderz"order/orders/batchCancelOpenOrderszorder/orders/{id}/submitcancelzorder/orders/batchcancelzdw/withdraw/api/createzdw/withdraw-virtual/{id}/cancelzdw/transfer-in/marginzdw/transfer-out/marginzmargin/orderszmargin/orders/{id}/repayzcross-margin/transfer-inzcross-margin/transfer-outzcross-margin/orders)zcross-margin/orders/{id}/repayzstable-coin/exchangezsubuser/transferr   zapi/v2/summary.jsonzv2/market-statuszv1/common/symbolszv1/common/currencyszv2/settings/common/currencieszv2/reference/currencieszv1/common/timestampzv1/common/exchangezv1/settings/common/chainszv1/settings/common/currencyszv1/settings/common/symbolszv2/settings/common/symbolsz!v1/settings/common/market-symbolszmarket/history/candleszmarket/history/klinezmarket/detail/mergedzmarket/tickerszmarket/detail)market/depthmarket/trademarket/history/tradez
market/etpzv2/etp/referencezv2/etp/rebalancezv1/account/accountsz(v1/account/accounts/{account-id}/balancezv2/account/valuationzv2/account/asset-valuationzv1/account/historyzv2/account/ledgerzv2/point/accountzv2/account/deposit/addresszv2/account/withdraw/quotazv2/account/withdraw/addresszv1/query/deposit-withdrawz!v1/query/withdraw/client-order-idzv2/user/api-keyzv2/user/uidzv2/sub-user/user-listzv2/sub-user/user-statezv2/sub-user/account-listzv2/sub-user/deposit-addresszv2/sub-user/query-depositzv1/subuser/aggregate-balancezv1/account/accounts/{sub-uid}zv1/order/openOrderszv1/order/orders/{order-id}zv1/order/orders/getClientOrderz&v1/order/orders/{order-id}/matchresultz'v1/order/orders/{order-id}/matchresultszv1/order/orderszv1/order/historyzv1/order/matchresultszv2/reference/transact-fee-ratezv2/algo-orders/openingzv2/algo-orders/historyzv2/algo-orders/specific)zv1/margin/loan-infozv1/margin/loan-orderszv1/margin/accounts/balancezv1/cross-margin/loan-infozv1/cross-margin/loan-ordersz v1/cross-margin/accounts/balancev2/account/repaymentzv1/stable-coin/quotezv1/stable_coin/exchange_ratezv2/etp/transactionszv2/etp/transactionzv2/etp/limitzv1/account/transferzv1/futures/transferzv2/point/transferzv2/account/transferzv1/dw/withdraw/api/createz+v1/dw/withdraw-virtual/{withdraw-id}/cancelzv2/sub-user/deduct-modezv2/sub-user/creationzv2/sub-user/managementzv2/sub-user/tradable-marketzv2/sub-user/transferabilityzv2/sub-user/api-key-generationz v2/sub-user/api-key-modificationzv2/sub-user/api-key-deletionzv1/subuser/transferzv1/trust/user/active/creditzv1/order/orders/placezv1/order/batch-orderszv1/order/auto/placez'v1/order/orders/{order-id}/submitcancelz'v1/order/orders/submitCancelClientOrderz%v1/order/orders/batchCancelOpenOrderszv1/order/orders/batchcancelzv2/algo-orders/cancel-all-afterzv2/algo-orderszv2/algo-orders/cancellationr   zv1/dw/transfer-in/marginzv1/dw/transfer-out/marginzv1/margin/ordersz!v1/margin/orders/{order-id}/repayzv1/cross-margin/transfer-inzv1/cross-margin/transfer-outzv1/cross-margin/orders)z'v1/cross-margin/orders/{order-id}/repayzv1/stable-coin/exchangezv2/etp/creationzv2/etp/redemptionzv2/etp/{transactId}/cancelzv2/etp/batch-cancel)r   r   zapi/v1/timestampz
heartbeat/zapi/v1/contract_contract_infozapi/v1/contract_indexzapi/v1/contract_query_elementszapi/v1/contract_price_limitzapi/v1/contract_open_interestzapi/v1/contract_delivery_pricer   z
market/bboz%index/market/history/mark_price_klinezmarket/detail/batch_mergedzv2/market/detail/batch_mergedr   r   zapi/v1/contract_risk_infozapi/v1/contract_insurance_fundzapi/v1/contract_adjustfactorz!api/v1/contract_his_open_interestzapi/v1/contract_ladder_marginzapi/v1/contract_api_statez#api/v1/contract_elite_account_ratioz$api/v1/contract_elite_position_ratioz"api/v1/contract_liquidation_ordersz"api/v1/contract_settlement_recordszindex/market/history/indexzindex/market/history/basisz*api/v1/contract_estimated_settlement_pricez"api/v3/contract_liquidation_orderszswap-api/v1/swap_contract_infozswap-api/v1/swap_indexzswap-api/v1/swap_query_elementszswap-api/v1/swap_price_limitzswap-api/v1/swap_open_interestzswap-ex/market/depthzswap-ex/market/bbozswap-ex/market/history/klinez*index/market/history/swap_mark_price_klinezswap-ex/market/detail/mergedz%v2/swap-ex/market/detail/batch_mergedz-index/market/history/swap_premium_index_klinez"swap-ex/market/detail/batch_mergedzswap-ex/market/tradezswap-ex/market/history/tradezswap-api/v1/swap_risk_infozswap-api/v1/swap_insurance_fundzswap-api/v1/swap_adjustfactorz"swap-api/v1/swap_his_open_interestzswap-api/v1/swap_ladder_marginzswap-api/v1/swap_api_statez$swap-api/v1/swap_elite_account_ratioz%swap-api/v1/swap_elite_position_ratioz+swap-api/v1/swap_estimated_settlement_pricez#swap-api/v1/swap_liquidation_ordersz#swap-api/v1/swap_settlement_recordszswap-api/v1/swap_funding_ratez#swap-api/v1/swap_batch_funding_ratez(swap-api/v1/swap_historical_funding_ratez#swap-api/v3/swap_liquidation_ordersz.index/market/history/swap_estimated_rate_klinezindex/market/history/swap_basisz%linear-swap-api/v1/swap_contract_infozlinear-swap-api/v1/swap_indexz&linear-swap-api/v1/swap_query_elementsz#linear-swap-api/v1/swap_price_limitz%linear-swap-api/v1/swap_open_interestzlinear-swap-ex/market/depthzlinear-swap-ex/market/bboz#linear-swap-ex/market/history/klinez1index/market/history/linear_swap_mark_price_klinez#linear-swap-ex/market/detail/mergedz)linear-swap-ex/market/detail/batch_mergedz,v2/linear-swap-ex/market/detail/batch_mergedzlinear-swap-ex/market/tradez#linear-swap-ex/market/history/tradez!linear-swap-api/v1/swap_risk_infoz2swap-api/v1/linear-swap-api/v1/swap_insurance_fundz$linear-swap-api/v1/swap_adjustfactorz*linear-swap-api/v1/swap_cross_adjustfactorz)linear-swap-api/v1/swap_his_open_interestz%linear-swap-api/v1/swap_ladder_marginz+linear-swap-api/v1/swap_cross_ladder_marginz!linear-swap-api/v1/swap_api_state)z,linear-swap-api/v1/swap_cross_transfer_statez)linear-swap-api/v1/swap_cross_trade_statez+linear-swap-api/v1/swap_elite_account_ratioz,linear-swap-api/v1/swap_elite_position_ratioz*linear-swap-api/v1/swap_liquidation_ordersz*linear-swap-api/v1/swap_settlement_recordsz$linear-swap-api/v1/swap_funding_ratez*linear-swap-api/v1/swap_batch_funding_ratez/linear-swap-api/v1/swap_historical_funding_ratez*linear-swap-api/v3/swap_liquidation_ordersz4index/market/history/linear_swap_premium_index_klinez5index/market/history/linear_swap_estimated_rate_klinez&index/market/history/linear_swap_basisz2linear-swap-api/v1/swap_estimated_settlement_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_rate   zapi/v1/lightning_close_positionzapi/v1/contract_order_infozapi/v1/contract_order_detailzapi/v1/contract_openorderszapi/v1/contract_hisorderszapi/v1/contract_hisorders_exactzapi/v1/contract_matchresultsz"api/v1/contract_matchresults_exactzapi/v3/contract_hisorderszapi/v3/contract_hisorders_exactzapi/v3/contract_matchresultsz"api/v3/contract_matchresults_exactzapi/v1/contract_trigger_orderzapi/v1/contract_trigger_cancelz!api/v1/contract_trigger_cancelallz"api/v1/contract_trigger_openordersz!api/v1/contract_trigger_hisorderszapi/v1/contract_tpsl_orderzapi/v1/contract_tpsl_cancelzapi/v1/contract_tpsl_cancelallzapi/v1/contract_tpsl_openorderszapi/v1/contract_tpsl_hisordersz#api/v1/contract_relation_tpsl_orderzapi/v1/contract_track_orderzapi/v1/contract_track_cancelzapi/v1/contract_track_cancelallz api/v1/contract_track_openorderszapi/v1/contract_track_hisordersz"swap-api/v1/swap_balance_valuationzswap-api/v1/swap_account_infozswap-api/v1/swap_position_infoz&swap-api/v1/swap_account_position_infozswap-api/v1/swap_sub_authz!swap-api/v1/swap_sub_account_listz&swap-api/v1/swap_sub_account_info_listz!swap-api/v1/swap_sub_account_infoz"swap-api/v1/swap_sub_position_infoz!swap-api/v1/swap_financial_recordz'swap-api/v1/swap_financial_record_exactz(swap-api/v1/swap_user_settlement_recordsz%swap-api/v1/swap_available_level_ratezswap-api/v1/swap_order_limitzswap-api/v1/swap_feezswap-api/v1/swap_transfer_limitzswap-api/v1/swap_position_limitz$swap-api/v1/swap_master_sub_transferz+swap-api/v1/swap_master_sub_transfer_recordz!swap-api/v3/swap_financial_recordz'swap-api/v3/swap_financial_record_exactzswap-api/v1/swap-cancel-afterzswap-api/v1/swap_orderzswap-api/v1/swap_batchorderzswap-api/v1/swap_cancelzswap-api/v1/swap_cancelallz)swap-api/v1/swap_lightning_close_positionz"swap-api/v1/swap_switch_lever_ratezswap-api/v1/swap_order_infozswap-api/v1/swap_order_detailzswap-api/v1/swap_openorderszswap-api/v1/swap_hisordersz swap-api/v1/swap_hisorders_exactzswap-api/v1/swap_matchresultsz#swap-api/v1/swap_matchresults_exactzswap-api/v3/swap_matchresultsz#swap-api/v3/swap_matchresults_exactzswap-api/v3/swap_hisordersz swap-api/v3/swap_hisorders_exactzswap-api/v1/swap_trigger_orderzswap-api/v1/swap_trigger_cancelz"swap-api/v1/swap_trigger_cancelallz#swap-api/v1/swap_trigger_openordersz"swap-api/v1/swap_trigger_hisorderszswap-api/v1/swap_tpsl_orderzswap-api/v1/swap_tpsl_cancelzswap-api/v1/swap_tpsl_cancelallz swap-api/v1/swap_tpsl_openorderszswap-api/v1/swap_tpsl_hisordersz$swap-api/v1/swap_relation_tpsl_orderzswap-api/v1/swap_track_orderzswap-api/v1/swap_track_cancelz swap-api/v1/swap_track_cancelallz!swap-api/v1/swap_track_openordersz swap-api/v1/swap_track_hisordersz,linear-swap-api/v1/swap_lever_position_limitz2linear-swap-api/v1/swap_cross_lever_position_limitz)linear-swap-api/v1/swap_balance_valuationz$linear-swap-api/v1/swap_account_infoz*linear-swap-api/v1/swap_cross_account_infoz%linear-swap-api/v1/swap_position_infoz+linear-swap-api/v1/swap_cross_position_infoz-linear-swap-api/v1/swap_account_position_infoz3linear-swap-api/v1/swap_cross_account_position_infoz linear-swap-api/v1/swap_sub_authz(linear-swap-api/v1/swap_sub_account_listz.linear-swap-api/v1/swap_cross_sub_account_listz-linear-swap-api/v1/swap_sub_account_info_listz3linear-swap-api/v1/swap_cross_sub_account_info_listz(linear-swap-api/v1/swap_sub_account_infoz.linear-swap-api/v1/swap_cross_sub_account_infoz)linear-swap-api/v1/swap_sub_position_infoz/linear-swap-api/v1/swap_cross_sub_position_infoz(linear-swap-api/v1/swap_financial_recordz.linear-swap-api/v1/swap_financial_record_exactz/linear-swap-api/v1/swap_user_settlement_recordsz5linear-swap-api/v1/swap_cross_user_settlement_recordsz,linear-swap-api/v1/swap_available_level_ratez2linear-swap-api/v1/swap_cross_available_level_ratez#linear-swap-api/v1/swap_order_limitzlinear-swap-api/v1/swap_feez&linear-swap-api/v1/swap_transfer_limitz,linear-swap-api/v1/swap_cross_transfer_limitz&linear-swap-api/v1/swap_position_limitz,linear-swap-api/v1/swap_cross_position_limitz+linear-swap-api/v1/swap_master_sub_transferz2linear-swap-api/v1/swap_master_sub_transfer_recordz&linear-swap-api/v1/swap_transfer_innerz(linear-swap-api/v3/swap_financial_recordz.linear-swap-api/v3/swap_financial_record_exactzlinear-swap-api/v1/swap_orderz#linear-swap-api/v1/swap_cross_orderz"linear-swap-api/v1/swap_batchorderz(linear-swap-api/v1/swap_cross_batchorderzlinear-swap-api/v1/swap_cancelz$linear-swap-api/v1/swap_cross_cancelz!linear-swap-api/v1/swap_cancelallz'linear-swap-api/v1/swap_cross_cancelallz)linear-swap-api/v1/swap_switch_lever_ratez/linear-swap-api/v1/swap_cross_switch_lever_ratez0linear-swap-api/v1/swap_lightning_close_positionz6linear-swap-api/v1/swap_cross_lightning_close_positionz"linear-swap-api/v1/swap_order_infoz(linear-swap-api/v1/swap_cross_order_infoz$linear-swap-api/v1/swap_order_detailz*linear-swap-api/v1/swap_cross_order_detailz"linear-swap-api/v1/swap_openordersz(linear-swap-api/v1/swap_cross_openordersz!linear-swap-api/v1/swap_hisordersz'linear-swap-api/v1/swap_cross_hisordersz'linear-swap-api/v1/swap_hisorders_exactz-linear-swap-api/v1/swap_cross_hisorders_exactz$linear-swap-api/v1/swap_matchresultsz*linear-swap-api/v1/swap_cross_matchresultsz*linear-swap-api/v1/swap_matchresults_exactz0linear-swap-api/v1/swap_cross_matchresults_exactz&linear-swap-api/v1/linear-cancel-afterz,linear-swap-api/v1/swap_switch_position_modez2linear-swap-api/v1/swap_cross_switch_position_modez$linear-swap-api/v3/swap_matchresultsz*linear-swap-api/v3/swap_cross_matchresultsz*linear-swap-api/v3/swap_matchresults_exactz0linear-swap-api/v3/swap_cross_matchresults_exactz!linear-swap-api/v3/swap_hisordersz'linear-swap-api/v3/swap_cross_hisordersz'linear-swap-api/v3/swap_hisorders_exactz-linear-swap-api/v3/swap_cross_hisorders_exactz-linear-swap-api/v3/fix_position_margin_changez+linear-swap-api/v3/swap_switch_account_typez)linear-swap-api/v3/linear_swap_fee_switchz%linear-swap-api/v1/swap_trigger_orderz+linear-swap-api/v1/swap_cross_trigger_orderz&linear-swap-api/v1/swap_trigger_cancelz,linear-swap-api/v1/swap_cross_trigger_cancelz)linear-swap-api/v1/swap_trigger_cancelallz/linear-swap-api/v1/swap_cross_trigger_cancelallz*linear-swap-api/v1/swap_trigger_openordersz0linear-swap-api/v1/swap_cross_trigger_openordersz)linear-swap-api/v1/swap_trigger_hisordersz/linear-swap-api/v1/swap_cross_trigger_hisordersz"linear-swap-api/v1/swap_tpsl_orderz(linear-swap-api/v1/swap_cross_tpsl_orderz#linear-swap-api/v1/swap_tpsl_cancelz)linear-swap-api/v1/swap_cross_tpsl_cancelz&linear-swap-api/v1/swap_tpsl_cancelallz,linear-swap-api/v1/swap_cross_tpsl_cancelallz'linear-swap-api/v1/swap_tpsl_openordersz-linear-swap-api/v1/swap_cross_tpsl_openordersz&linear-swap-api/v1/swap_tpsl_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   rM   r   r   trading0.002)feeSide	tierBased
percentagemakertaker
exceptions)zTcontract is restricted of closing positions on API.  Please contact customer servicemaintainzAPI key has no permission4031010100310131017103410361039104110471048106110511066106710941220130314614007zbad-requestzvalidation-format-errorzvalidation-constraints-requiredzbase-date-limit-errorzapi-not-support-temp-addrtimeoutzgateway-internal-errorz)account-frozen-balance-insufficient-errorzinvalid-amountz!order-limitorder-amount-min-errorz!order-limitorder-amount-max-errorz"order-marketorder-amount-min-errorz order-limitorder-price-min-errorz order-limitorder-price-max-errorzorder-stop-order-hit-triggerzorder-value-min-errorzorder-invalid-pricezorder-holding-limit-failedz order-orderprice-precision-errorzorder-etp-nav-price-max-errorzorder-orderstate-errorzorder-queryorder-invalidzorder-update-errorzapi-signature-check-failedzapi-signature-not-validzbase-record-invalidzbase-symbol-trade-disabledzbase-symbol-errorzsystem-maintenancez#base-request-exceed-frequency-limitzinvalid symbol)zsymbol trade not open nowzrequire-symbolzinvalid-addresszbase-currency-chain-errorzdw-insufficient-balancezbase-withdraw-fee-errorzdw-withdraw-min-limitzrequest limit)broadexactprecisionModeoptionsinclude_OS_certificatestypes)rM   r   r   timeDifferencer   adjustForTimeDifferenceuseHistoricalEndpointForSpotr   
includeFeedefaultTypedefaultSubTyper   defaultNetworkERC20defaultNetworksBTCTRC20)ETHr  USDTnetworksTRXr   SOLSOLANAHRC20HECOBEP20BSCXMRLTCXRPXLMCRONOSCROGLMRPOLYGONMATICBTTCUBEIOSTNEOKLAYEOSTHETANASNULSQTUMFTMCELODOGE	DOGECHAINNEARSTEPBITCICARDANOADAETCLUKMINEPLEXDASHZECIOTANEON3XEMHCLSKDCRBTGSTEEMBTSICXWAVESCMTBTMVETXZCACTSMTBCDWAXWAX1WICCELFZILELABCXSBTCBIFICTXCWANPOLYXPAIWTCDGBXVGAACAESEELEBCVGRSARDRNANOZENRBTCBSVGASXTZLAMBCVNT1DOCKSCKMDETNTOPIRISUGASTTNEWTONVSYSFSNBHDONEEMCKBEOSSHIVERVNDOTKSMBANDOEP4NBSFISARHBARFILMASSKAVAXYMENJCRUSTICPCSPRFLOWIOTXLATAPTXCHMINAXECECASHXPRTCCAACAAOTICOTIAKTARSASTRAZEROBLDBRISECOREDESODFIEGLDERGETHFETHFAIRETHWEVMOSFIOFLRFINSCHIAKMAKYVEMEVMOVRNODLOASOSMOPAYCOINPOKTPYGREISCRTSDNSEISGBSUISXPSOLARSYSTENETTONUNQUYUWEMIXXDCXPLA)r  r  fetchOrdersByStatesMethod spot_private_get_v1_order_orders!createMarketBuyOrderRequiresPricelanguagezen-USbroker
AA03022abcaccountsByTypefutures)rM   fundingrP   accountsByIdotcpointsuper-margin
investmentborrowgrid-tradingdeposit-earningotc-options)
rM   rN   r  r  r  r  r  r  r  r  )rJ   r  )
stop-limitbuy-stop-limitsell-stop-limitstop-limit-fokbuy-stop-limit-foksell-stop-limit-foklimitz	buy-limitz
sell-limitioczbuy-ioczsell-ioclimit-makerzbuy-limit-makerzsell-limit-makerr  r  r  	limit-fokzbuy-limit-fokzsell-limit-fokr  r  r  )stopOrderTypeslimitOrderTypes)typesByAccountrM   GFNGLTHEMISGAMECOMHITCHAINPENTASUPERBITCOIN	SOULSAVERBITCOINFILEzFTX Users Debt)	NGLGETGTCHITPNTrd  SOULre  FUD)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingicebergselfTradePreventionleveragemarketBuyByCostmarketBuyRequiresPricemax  x      )r  r  daysBack	untilDayssymbolRequired)r  triggerr  r  )r  r  r  r  r     )r  r  r  r  r  r  r  gUUUUUU?)r  r  r  r  r  r  daysBackCanceledr    )	sandboxr_   r`   r   r   r   r   rq   r   )r  r  r  r     r  )r  r  r  r  Z   )r  r  r  r  r  )r  r  r  r  r  r  r     )extendsr_   r`   r   r   r   rq   r   r&  forDerivatives)r   r   )rM   r'  rO   rP   )commonCurrenciesfeatures)deep_extendsuperr9   describe
userAgentsparse_numberr3   r'   r&   r(   r+   r.   r-   r,   r*   r4   r2   r1   r6   )self	__class__s    B/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/htx.pyr,  htx.describe"   sv3   c4 9 ; H>
%H>
EH>
 $H>
 	H>

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

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

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

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
r   r  rM   typeNrP   rO   datar9  )rK  r  rD  contractPublicGetApiV1TimestampspotPublicGetV1CommonTimestampsafe_integer_2)r/  rM  r  r  rX  rP  s         r1  
fetch_timehtx.fetch_timeJ  s     //$,,R@&&t||]FK=5H$&.;;FCH::6BH ""8VT::r3  Nfeemarketc                     U R                  US5      nUU R                  X25      U R                  US5      U R                  US5      S S S.$ )NsymbolactualMakerRateactualTakerRate)r@  rb  r   r   r   r   )rD  safe_symbolsafe_number)r/  r_  r`  marketIds       r1  parse_trading_feehtx.parse_trading_feeh  sY     ##C2&&x8%%c+<=%%c+<=
 	
r3  rb  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R	                  US0 5      nU R                  Xs5      $ )a?  
fetch the trading fees for a market

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
symbolsr=   rY  r   )rA  r`  (spotPrivateGetV2ReferenceTransactFeeRateextendrK  rh  )r/  rb  rM  r`  requestrP  rY  firsts           r1  fetch_trading_feehtx.fetch_trading_fee|  s     	V$vd|
 @@WA]^  x4a,%%e44r3  rk  c                     U R                  5         Uc  U R                  n0 n[        S[        U5      5       H*  nX   nU R	                  U R                  U5      U5      X5'   M,     U$ )Nr   )rA  rk  rangelenfetch_trading_limits_by_id	market_id)r/  rk  rM  resultirb  s         r1  fetch_trading_limitshtx.fetch_trading_limits  sd     	?llGq#g,'AZF!<<T^^F=SU[\FN ( r3  r=   c                     SU0nU R                  U R                  X25      5      nU R                  U R                  US0 5      5      $ )a   
@ignore

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

       :param str id: market id
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns dict: the limits object of a market structure
       rb  rY  )spotPublicGetV1CommonExchangerm  parse_trading_limitsrK  )r/  r=   rM  rn  rP  s        r1  ru  htx.fetch_trading_limits_by_id  sK     b
 55dkk'6RS" ((62)NOOr3  c                 V    USU R                  US5      U R                  US5      S.0S.$ )Namountzlimit-order-must-greater-thanzlimit-order-must-less-thanminr  )r@  limits)rf  )r/  r  rb  rM  s       r1  r}  htx.parse_trading_limits  s@    " ++F4ST++F4PQ
 	
r3  c                 l    U R                  U[        U R                  U   S   S   U R                  5      $ )N	precisioncost)decimal_to_precisionr5   marketsr  )r/  rb  r  s      r1  cost_to_precisionhtx.cost_to_precision  s4    ((xf9Mk9Z[a9bdhdvdvwwr3  c                    U R                   S   (       a  U R                  5         SnU R                  USS0 5      u  p!/ n/ n[        UR	                  5       5      n[        S[        U5      5       H  nXV   nU R                  X'5      (       d  M  US:X  a$  UR                  U R                  SSU5      5        MI  US:X  a$  UR                  U R                  SSU5      5        Ms  US:X  d  M{  UR                  U R                  S	SU5      5        UR                  U R                  S
SU5      5        M     Un[        S[        U5      5       H  nU R                  X4U   5      nM     U$ )a  
retrieves data on all markets for huobi

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r  Nr   r  r   rM   r   r   rO   rP   )r  load_time_differencehandle_option_and_paramslistkeysrs  rt  	safe_boolappend"fetch_markets_by_type_and_sub_typearray_concat)r/  rM  r  
allMarketspromisesr  rx  keys           r1  fetch_marketshtx.fetch_markets  s@    <<12%%'55fngWYZ
EJJL!q#d)$A'C~~e))&=OOD$K$KFTXZ`$abH_OOD$K$KDRZ\b$cdI%OOD$K$KFT]_e$fgOOD$K$KHV_ag$hi % q#h-(A**:{CJ )r3  rX  r6  c                 f   US:H  n0 nSnU(       d  US:X  a&  SUS'   U R                  U R                  XS5      5      nOtUS:X  aM  US:X  a!  U R                  U R                  XS5      5      nOGUS:X  a   U R                  U R                  XS5      5      nO U R	                  U R                  XS5      5      nU R                  US	/ 5      n[        U5      nUS
:  a*  [        U R                  S-   U R                  U5      -   5      e/ n	[        S[        U5      5       GH  n
Xz   nSnSnSnSnSnSU;   nU(       + nSnSnSnSnU(       Ga  U R                  US5      nUR                  5       nU R                  US5      nU R                  US5      nUSLnU(       + nUSLnU(       + nU(       aC  SnUR                  S5      nU R                  US5      nU R                  US
5      nU(       a  UOUnOU(       aW  SnU R                  US5      nU(       a  SnUnOrU R                  US5      nUR                  S5      nU R                  US
5      nUnO:SnU R                  US5      nU R                  US5      nX-   nUR                  5       nU R                  U5      nU R                  U5      nU R                  U5      nUS-   U-   nSnU(       aO  U(       a	  USU-   -  nOU(       a  USU-   -  nU(       a)  U R!                  US5      nUSU R#                  U5      -   -  nU R%                  US5      n U R%                  US5      n!U R%                  US5      n"U R%                  US5      n#U(       a  U(       a  U n#O	U(       a  U n!Sn$Sn%Sn&Sn'Sn(Sn)U(       a  U R'                  U R)                  U R                  US5      5      5      n$U R'                  U R)                  U R                  US5      5      5      n%U R'                  U R)                  U R                  US5      5      5      n&U R'                  S 5      n'U R'                  S 5      n(U R                  US!5      n*U*S":H  n)O\U R%                  US#5      n$U R'                  S$5      n%U R'                  S%5      n'U R'                  S&5      n(U R!                  US'5      n+U+S
:H  n)U R                  US(S$5      n,U R                  US)S$5      n-[*        R,                  " U,S$5      =(       d    [*        R,                  " U-S$5      n.Sn/U R                  US*5      n0U0bZ  U R/                  U05      n1U1S   U1S
   -   U1S+   -   U1S,   -   S-   U1S-   -   U1S.   -   S-   U1S/   -   U1S0   -   S1-   n0U R1                  U05      n/U	R3                  0 S2U_S3U_SU_S4U_S5U_S6U_S7U_S8U_S9U_S:U_SU_S;U=(       a    U._SU_SU_S<S_S=U)_S>U_UUU(U'U UU R5                  U5      SSU%U$U&S?.U R'                  S$5      U R'                  U,5      U R'                  U-5      S@.U#U"SA.SSSA.U!SSA.SB.U/USC.E5        GM     U	$ )Da  
@ignore
       retrieves data on all markets of a certain type and/or subtype

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

       :param str [type]: 'spot', 'swap' or 'future'
       :param str [subType]: 'linear' or 'inverse'
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns dict[]: an array of objects representing market data
       rM   Nr   allbusiness_typer   rP   rO   rY  r   z, fetchMarkets() returned an empty response: r   contract_codeFdelivery_date-rb  USDpairzbase-currencyzquote-currency/:delivery_timecontract_sizezmin-order-valuezmax-order-amtzmin-order-amtzprice-precisionzamount-precisionzvalue-precisionr   stateonline
price_tick1z0.0002z0.0005contract_statuszleverage-ratiozsuper-margin-leverage-ratiocreate_dater     r   r         z	 00:00:00r=   lowercaseIdbasequotesettlebaseIdquoteIdsettleIdrX  rN   rQ   activer   )r  pricer  )r  r  superMaxr  )r  r  r  r  )r   r   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr@  )0contractPublicGetLinearSwapApiV1SwapContractInform  *contractPublicGetApiV1ContractContractInfo*contractPublicGetSwapApiV1SwapContractInfospotPublicGetV1CommonSymbols	safe_listrt  r0   r=   jsonrs  rD  lowersplitsafe_string_lowersafe_currency_codesafe_integeryymmddrf  r.  parse_precisionr7   	string_gtstring_to_chars_arrayrL  r  iso8601)2r/  rX  r6  rM  isSpotrn  rP  r  
numMarketsrw  rx  r`  r  r  r  r=   r  r   rM   rO   rP   r   r   r  r  partsr  r  r  r  rb  r  r  minCost	maxAmount	minAmountpricePrecisionamountPrecisioncostPrecisionr   r   r  r  contractStatusleverageRatiosuperLeverageRatiohasLeverager  createdDatecreatedArrays2                                                     r1  r  &htx.fetch_markets_by_type_and_sub_type  s    &.("+0(PPQUQ\Q\]dQmnI%8##NNt{{[bOklHV^#NNt{{[bOklH88W9UVHn ..626\
>!$'',Z"Z]a]f]fgo]p"pqqq#g,'AZFFGHBK'61H<DDFFG%%fo> hhj $ 0 0 I $ 0 0 I&d2!z&d2$*!DHHSME!33FHEF"44UA>G)0vgH#D!33FHEF"'#)#//? $

3"&"8"8"B#*))&/B**63CD% hhj**62D++G4E,,X6FCZ%'FFcDj(FcEk)F!..vGFcDKK$777F++FODL&&v/@AG((AI((AI ,I*G!N"O MEEF!%!2!243G3GHXHXY_arHs3t!u"&"3"3D4H4HIYIYZ`btIu4v"w $ 1 1$2F2FtGWGWX^`qGr2s t))'2))'2((98+!%!1!1&,!G"&"3"3C"8))(3))(3!%!2!26;L!M(A- ,,V5EsKM!%!1!1&:WY\!]!++M3?m7CTCTUgilCmK G**6=AK&#99+F*1oQ?,q/QT`abTccfiilxyzl{{  K  LM  N  N  QT  T  Wc  de  Wf  f  iu  vw  ix  x  {F  F..5MM 5b5{5 &5 	5
 5 &5 &5 75 H5 5 5 4/K5 5 &5 %5  &!5" H#5$ !" , "&,,v"6"-+)  $005#00?$($5$56H$I!  )(
  $#
  '#& #i5 5Y (D r3  symbolOrMarketIdc                 >   XR                   ;   a  U$ SU R                  ;  a  0 U R                  S'   U R                  U R                  S0 5      nX;   a  X!   $ U R                  U R                   SS5      nSSSSS.n[	        S	[        U5      5       Hx  nX5   nU R                  US
0 5      nU R                  US5      nXH   n	US   (       a  US   S-   US   -   S-   U	-   O
US   S-   U	-   n
X:X  d  M`  US   nXR                  S   U'   Us  $    XR                  S   U'   U$ )NfutureMarketIdsForSymbolsrP   TCWNWCQNQ)	this_week	next_weekquarternext_quarterr   r@  contract_typer   r  r  r  _rb  )r  r  	safe_dict	filter_byrs  rt  rK  rD  )r/  r  r  futureMarketsfuturesCharsMapsrx  r`  r@  contractTypecontractSuffixconstructedIdrb  s               r1  "try_get_symbol_from_future_markets&htx.try_get_symbol_from_future_markets'  sh   ||+##
 ,t||;8:DLL45$(NN4<<A\^`$a!8,>>t||XtD 	"
 q#m,-A"%F??6626D++D/BL-;N]cdl]mF6NS06'?BSH>Ysy  {A  tB  EH  tH  KY  tYM0)NT89:JK . GW012BCr3  tickerc                    U R                  USS5      nU R                  X25      nU R                  U5      nU R                  USS5      nS nS nS nS n	SU;   am  US   bC  [	        US   [
        5      (       a+  U R                  US   S5      nU R                  US   S5      nO$U R                  US5      nU R                  US5      nS	U;   am  US	   bC  [	        US	   [
        5      (       a+  U R                  US	   S5      nU R                  US	   S5      n	O$U R                  US	5      nU R                  US
5      n	U R                  US5      n
U R                  US5      nU R                  US5      nU R                  US5      nU R                  0 SU_SU_SU R                  U5      _SU R                  US5      _SU R                  US5      _SU_SU_S	U_SU	_SS _SU
_SU_SU_SS _SS _SS _SS _UUUS.EU5      $ )Nrb  r  r9  	quoteTimebidr   r   bidSizeaskaskSizeopencloser  vol	timestamprT  highlow	bidVolume	askVolumevwaplastpreviousClosechanger   average)
baseVolumequoteVolumer@  )	safe_string_2re  r  r\  
isinstancer  rD  safe_tickerr  )r/  r  r`  rg  rb  r  r  r  r  r  r  r  r	  r
  s                 r1  parse_tickerhtx.parse_tickerI  s   \ %%fhH!!(388@''kB			F?e}(Zut-L-L&&ve}a8 ,,VE]A>	&&vu5 ,,VY?	F?e}(Zut-L-L&&ve}a8 ,,VE]A>	&&vu5 ,,VY?	/  1%%fh7
&&vu5 !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 3!
 !
 3!
 !
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	r3  c                    U R                  5         U R                  U5      n0 nSnUS   (       a)  US   US'   U R                  U R                  XB5      5      nOUS   (       af  US   (       a)  US   US'   U R	                  U R                  XB5      5      nO[US   (       a(  US   US'   U R                  U R                  XB5      5      nO(US   US'   U R                  U R                  XB5      5      nU R                  US	0 5      nU R                  Xc5      nU R                  US
5      nXS'   U R                  U5      US'   U$ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

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

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r=   r  r   rP   rb  rO   tickr9  r  rT  )rA  r`  /contractPublicGetLinearSwapExMarketDetailMergedrm  #contractPublicGetMarketDetailMerged)contractPublicGetSwapExMarketDetailMergedspotPublicGetMarketDetailMergedrK  r  r  r  )	r/  rb  rM  r`  rn  rP  r  r  r  s	            r1  fetch_tickerhtx.fetch_ticker  s>    	V$('-d|GO$KKDKKX_LhiHIh$*4L!CCDKKPWD`a+1$<(II$++V]Jfg &tGH;;DKK<XYHX x4""40%%h5	'{!\\)4zr3  c                    U R                  5         U R                  U5      nU R                  US5      nSnUb  U R                  U5      nSU;   =(       d    SU;   nSnSnU R	                  SXB5      u  pbU R                  SXB5      u  pr0 nUS:H  n	US:H  n
US:H  nUS	:H  nUS
:H  nSnU	(       a  U(       a  U(       a@  U
(       a  SUS'   OU(       a  SUS'   OSUS'   U R                  U R                  X5      5      nOU(       ah  U
(       a!  U R                  U R                  X5      5      nOxU(       a!  U R                  U R                  X5      5      nOP[        U R                  S-   5      e[        U R                  S-   5      eU R                  U R                  X5      5      nU R                  USS/ 5      nU R                  XU5      nU R                  USU5      $ )a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

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

:param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
r   Nr6  r  r   rM   rP   rO   r   r   r  r  za fetchTickers() you have to set params["type"] to either "swap" or "future" for inverse contractsz_ fetchTickers() you have to set params["subType"] to either "linear" or "inverse" for contractsrY  ticksrb  )rA  market_symbolsrD  r`  rB  handle_sub_type_and_params4contractPublicGetLinearSwapExMarketDetailBatchMergedrm  (contractPublicGetMarketDetailBatchMerged.contractPublicGetSwapExMarketDetailBatchMergedr/   r=   spotPublicGetMarketTickerssafe_list_2parse_tickersfilter_by_array_tickers)r/  rk  rM  ro  r`  isSubTypeRequestedrX  r6  rn  r  rP   rO   r   r   rP  
rawTickerstickerss                    r1  fetch_tickershtx.fetch_tickers  s    	%%g.  !,[['F'61Q&7P99.&Y99.&Y&.("X%i'+/8GO,/5GO,/4GO,TTUYU`U`ahUqr#LLT[[Y`MijH#RRSWS^S^_fSopH&tww  2U  (U  V  V"477  .O  $O  P  P66t{{77STHf %%hD
$$Z&A++GXwGGr3  c                 ,   U R                  5         U R                  U5      nU R                  U5      nSnSnU R                  SX25      u  pRU R	                  SX25      u  pBSnUS:X  d  US:X  a  US:X  a  U R                  U5      nOZUS:X  a  US:X  a  U R                  U5      nO<US:X  a  US:X  a  U R                  U5      nO[        U R                  S-   U-   S-   5      eU R                  US	0 5      nU R                  US
/ 5      nU R                  X5      $ )a8  
fetches the last price for multiple markets

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

:param str[] [symbols]: unified symbols of the markets to fetch the last prices
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of lastprices structures
Nr   rO   rP   r   r   z$ fetchLastPrices() does not support z markets yetr  rY  )rA  r  get_market_from_symbolsr  rB  (contractPublicGetLinearSwapExMarketTrade"contractPublicGetSwapExMarketTradecontractPublicGetMarketTrader/   r=   rK  r  parse_last_prices)	r/  rk  rM  r`  rX  r6  rP  r  rY  s	            r1  fetch_last_priceshtx.fetch_last_pricesb	  s'    	%%g.--g699:KV\99:KV\V^!1H9LDDVLH4 fn7i#7>>vFH. hW	%988@H0 tww)OORVVYgghhx4~~dFB/%%d44r3  c                     U R                  USS5      nU R                  X25      nU R                  US5      nU R                  US5      nUS   S S UUUS.$ )Nrb  r  r  	direction)rb  r  rT  r  sider@  )r  safe_marketrf  rD  )r/  entryr`  rg  r  r1  s         r1  parse_last_pricehtx.parse_last_price	  sm    %%eXG!!(3  0$$UK8	 X&
 	
r3  r  c                    U R                  5         U R                  U5      nSS0nSnUS   (       a)  US   US'   U R                  U R                  XS5      5      nOUS   (       af  US   (       a)  US   US	'   U R	                  U R                  XS5      5      nOUS
   (       a(  US   US'   U R                  U R                  XS5      5      nOeUb:  US:w  a*  US:w  a$  US:w  a  US:w  a  [        U R                  S-   5      eUS:w  a  X%S'   US   US	'   U R                  U R                  XS5      5      nSU;   a  US   (       d*  [        U R                  S-   U R                  U5      -   5      eU R                  US5      nU R                  USU R                  US5      5      nU R                  XqU5      n	U R                  US5      U	S'   U	$ [        U R                  S-   U R                  U5      -   5      e)a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

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

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
rX  step0Nr   r=   r  r   rP   rb  rO   r   r         zP fetchOrderBook() limit argument must be None, 5, 10, 20, or 150, default is 150depthr  z+ fetchOrderBook() returned empty response: r9  rG   noncez2 fetchOrderBook() returned unrecognized response: )rA  r`  (contractPublicGetLinearSwapExMarketDepthrm  contractPublicGetMarketDepth"contractPublicGetSwapExMarketDepthr*   r=   spotPublicGetMarketDepthr+   r  rK  r  parse_order_bookr%   )
r/  rb  r  rM  r`  rn  rP  r  r  rw  s
             r1  fetch_order_bookhtx.fetch_order_book	  s    	V$ G

 ('-d|GO$DDT[[QXEabHIh$*4L!<<T[[=YZ+1$<(BB4;;wC_` QJUb[u{RU$TWW  0B  &B  C  C C<',G$ &tGH44T[[5QRH6 XF#*W WZ^ZcZcdlZm mnn??8V4D))$d6G6GRV6WXI**4CF"//i@F7OMDGG&ZZ]a]f]fgo]ppqqr3  tradec                 t   U R                  USS5      nU R                  X25      nUS   nU R                  USS5      nU R                  USSU5      nU R                  USS5      nU R                  US	5      nU R                  US
5      nUb  UR	                  S5      n	U	S   nU	S   nU R                  US5      n
U R                  USS5      nU R                  USS5      nU R                  USU5      nU R                  US5      nS nU R                  US5      nUc&  [        R                  " U R                  US5      5      nU R                  USS5      nU R                  U5      nU R                  US5      nUbG  Ub  [        R                  " US5      (       a(  U R                  US5      nUb  UnU R                  U5      nUb  UUS.nS nU R                  US5      nUb  UR                  S5      S:  a  UnOU R                  U/ SQ5      nU R                  UUUUU R                  U5      UUUU
UUUUS.U5      $ ) Nr  rb  r9  
created-at
created_atr  order-idorder_idr1  rX  r  r   r   roler  trade_pricefilled-amountr  trade_volumetrade_turnoverfilled-fees	trade_feezfee-currency	fee_assetzfilled-points0zfee-deduct-currencyr  currencyr=   )trade_idztrade-idr=   )r=   r@  orderr  rT  rb  rX  r2  takerOrMakerr  r  r  r_  )r  r3  r\  rD  r  r  r7   
string_negr  string_equalsfindsafe_string_n
safe_trader  )r/  rD  r`  rg  rb  r  rV  r2  rX  	typePartsrW  priceStringamountString
costStringr_  feeCostfeeCurrencyIdfeeCurrencyfilledPointsfeeDeductCurrencyr=   safeIds                         r1  parse_tradehtx.parse_trade-
  s|   ^ %%e_hG!!(3!''t\B	''|]IV	""5*jA{3v.

3IQ<DQ<D--eV<((G))%(K''~|L%%e-=>
""5-8?(()9)9%)MNG**5.+N--m<''?#G$9$9'3$G$G$($4$4U<Q$R!$0*G"&"9"9:K"LK'C !!%.&++c"2a"7B##E+IJB"Y/( " 
  	r3  sincec                     SnUb  U R                  U5      nSnU R                  SXe5      u  puUS:w  a  [        U R                  S-   5      eU R	                  XX4U5      $ )a  
fetch all the trades made from a single order

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

:param str id: order id
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nr   rM   z6 fetchOrderTrades() is only supported for spot markets)r`  rB  r/   r=   fetch_spot_order_trades)r/  r=   rb  ri  r  rM  r`  rN  s           r1  fetch_order_tradeshtx.fetch_order_trades
  sk     [[(F
!??@RTZc
tww)aabb++BfMMr3  c                     U R                  5         SU0nU R                  U R                  Xe5      5      nU R                  US   SX45      $ )a,  
@ignore
       fetch all the trades made from a single order

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

       :param str id: order id
       :param str symbol: unified market symbol
       :param int [since]: the earliest time in ms to fetch trades for
       :param int [limit]: the maximum number of trades to retrieve
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
       rH  rY  N)rA  .spotPrivateGetV1OrderOrdersOrderIdMatchresultsrm  parse_trades)r/  r=   rb  ri  r  rM  rn  rP  s           r1  rk  htx.fetch_spot_order_trades
  sR     	
 FFt{{SZGcd  &!14FFr3  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ SnUb  U R                  U5      nSnU R	                  SXd5      u  pt0 nSn	US:X  a`  Ub  U R                  U5      nUS   US'   Ub  X8S'   Ub  X(S	'   U R                  S
X5      u  pU R                  U R                  X5      5      n	GO=Uc  [        U R                  S-   5      eUS   US'   SUS'   Ub  X(S'   U R                  SX5      u  pUb  X8S'   US   (       ak  Sn
U R                  SU5      u  pU
c  SOU
n
U
S:X  a!  U R                  U R                  X5      5      n	OU
S:X  a   U R                  U R                  X5      5      n	O~US   (       at  US:X  a)  US   US'   U R                  U R                  X5      5      n	OEUS:X  a!  U R                  U R                  X5      5      n	O[        U R                  S-   U-   S-   5      eU R!                  U	S5      n[#        U[$        5      (       d  U R!                  US5      nU R'                  XX#5      $ )a  

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

fetch all trades made by the user
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch trades for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Fr   paginateNrM   r=   rb  size
start-timeend-timez+ fetchMyTrades() requires a symbol argumentr   r   
trade_type
start_timeend_time	page_sizer   crossisolatedr   rP   r  rO   z" fetchMyTrades() does not support  marketsrY  trades)rA  r  fetch_paginated_call_dynamicr`  rB  handle_until_option!spotPrivateGetV1OrderMatchresultsrm  r)   r=   handle_margin_mode_and_params7contractPrivatePostLinearSwapApiV3SwapMatchresultsExact<contractPrivatePostLinearSwapApiV3SwapCrossMatchresultsExact1contractPrivatePostApiV3ContractMatchresultsExact1contractPrivatePostSwapApiV3SwapMatchresultsExactr/   rK  r  r  rp  )r/  rb  ri  r  rM  rs  r`  rN  rn  rP  r  r~  s               r1  fetch_my_tradeshtx.fetch_my_trades
  s     	88R\]44_fUZcc[[(F
!??QW`

& !V,$*4L! "' (-%"66z7SOG==dkk'>Z[H~'2_(_``"(,GJ$%GL! (-%"66z7SOG ',$h!
%)%G%GY_%`"
)3);W*
+#[[\`\g\gho\xyH7*#``aealalmta}~H	")(.z(:GH%#UUVZVaVabiVrsH6)#UUVZVaVabiVrsH&tww1U'UXb'beo'oppF 62&$''__VX6F  >>r3  r!  c                    U R                  5         U R                  U5      n0 nUb  [        US5      US'   SnUS   (       af  US   (       a)  US   US'   U R                  U R	                  Xd5      5      nOUS   (       a(  US   US	'   U R                  U R	                  Xd5      5      nOUS
   (       a^  US   US	'   US   (       a!  U R                  U R	                  Xd5      5      nOSUS   (       a   U R                  U R	                  Xd5      5      nO(US   US'   U R                  U R	                  Xd5      5      nU R                  US/ 5      n/ n	[        S[        U5      5       HY  n
U R                  X   S/ 5      n[        S[        U5      5       H(  nU R                  X   U5      nU	R                  U5        M*     M[     U R                  U	S5      n	U R                  XS   X#5      $ )a  

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

get the list of most recent trades for a particular symbol
:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nr%  rt  rP   r   r=   rb  r   r  rO   rY  r   r  )rA  r`  r  #contractPublicGetMarketHistoryTraderm  /contractPublicGetLinearSwapExMarketHistoryTrade)contractPublicGetSwapExMarketHistoryTradespotPublicGetMarketHistoryTraderK  rs  rt  rg  r  sort_byfilter_by_symbol_since_limit)r/  rb  ri  r  rM  r`  rn  rP  rY  rw  rx  r~  jrD  s                 r1  fetch_tradeshtx.fetch_trades~  s    	V$
 !%.GFO(i $*4L!CCDKKPWD`a!+1$<(OOPTP[P[\cPlmF^'-d|GO$i II$++V]Jfg!OOPTP[P[\cPlm &tGH;;DKK<XYH2 x4q#d)$A__TWfb9F1c&k*((F;e$ + %
 fk2009I5XXr3  c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr=   r  r   r  r  r  )safe_timestamprf  )r/  ohlcvr`  s      r1  parse_ohlcvhtx.parse_ohlcv  sn     t,UF+UF+UE*UG,UH-
 	
r3  r   	timeframec           	      
   U R                  5         SnU R                  USS5      u  peU(       a  U R                  SXXBUS5      $ U R                  U5      nSU R	                  U R
                  X"5      0nU R                  USS/5      n	U R                  USS/5      nSn
U R                  US	5      u  pU
b  U R                  U
S-  5      OSnUS
   (       a  Ub  [        US5      US'   OSnU	co  U R                  U5      nSnUc   U R                  5       nXUS-
  -  -
  US'   UnO/U R                  US-  5      nXS'   U R                  XUS-
  -  5      nUb  UOUUS'   SnUS   (       Gab  US   (       a  US   US'   U	S:X  a"  U R                  U R                  X5      5      nGO9U	S:X  a"  U R!                  U R                  X5      5      nGOU	S:X  a'  [#        U R$                  S-   US   -   S-   U	-   S-   5      eU R'                  U R                  X5      5      nGOUS   (       a  US   US'   U	S:X  a"  U R)                  U R                  X5      5      nGOU	S:X  a'  [#        U R$                  S-   US   -   S-   U	-   S-   5      eU	S:X  a"  U R+                  U R                  X5      5      nGO3U R-                  U R                  X5      5      nGOUS   (       GaX  US   US'   US   (       a  U	S:X  a"  U R/                  U R                  X5      5      nGOU	S:X  a'  [#        U R$                  S-   US   -   S-   U	-   S-   5      eU	S:X  a"  U R1                  U R                  X5      5      nGOwU R3                  U R                  X5      5      nGOUUS   (       a  U	S:X  a"  U R)                  U R                  X5      5      nGO#U	S:X  a'  [#        U R$                  S-   US   -   S-   U	-   S-   5      eU	S:X  a!  U R+                  U R                  X5      5      nOU R-                  U R                  X5      5      nOUS   US'   SnU R                  USSS5      u  nnU(       d3  Ub  [        US5      US'   U R5                  U R                  X5      5      nOSUb  U R                  US-  5      US'   Ub  XS'   Ub  [        SU5      US'   U R7                  U R                  X5      5      nU R9                  US / 5      nU R;                  UXrX45      $ )!a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

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

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:param str [params.useHistoricalEndpointForSpot]: True/false - whether use the historical candles endpoint for spot markets or default klines endpoint
:returns int[][]: A list of candles ordered, open, high, low, close, volume
Fr   rs  r!  period	priceTyper  Nuntilr   r%  rt  r   fromtorP   r   r=   rb  markindexpremiumIndex rX  z has no api endpoint for z kline datar   r  rO   r  TrY  )rA  r  "fetch_paginated_call_deterministicr`  rD  r   r[  omithandle_param_integerparse_to_intr  parse_timeframesecondssum1contractPublicGetIndexMarketHistoryMarkPriceKlinerm  (contractPublicGetIndexMarketHistoryIndexr*   r=   #contractPublicGetMarketHistoryKline;contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline>contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline/contractPublicGetLinearSwapExMarketHistoryKline5contractPublicGetIndexMarketHistorySwapMarkPriceKline8contractPublicGetIndexMarketHistorySwapPremiumIndexKline)contractPublicGetSwapExMarketHistoryKlinespotPublicGetMarketHistoryKline!spotPublicGetMarketHistoryCandlesr  parse_ohlcvs)r/  rb  r  ri  r  rM  rs  r`  rn  r  r  untilSecondsdurationcalcualtedEndnowstartrP  useHistoricalrY  s                      r1  fetch_ohlcvhtx.fetch_ohlcv  sC   $ 	88zZ::<X]jprvwwV$d&&t	M
 &&vW/EF	6K#9:11&'B;@;Lt((6SW* "%eT"2  //	: $=,,.C&)	,B&BGFO$'M --edl;E&+FO$(HHU	4J$KM1=1IP](i $*4L!&#UUVZVaVabiVrsH')#LLT[[Y`MijH.0$TWWs]VF^%CFa%adm%mp}%}~~#GGT[HdeH!+1$<(&#__`d`k`kls`|}H')$TWWs]VF^%CFa%adm%mp}%}~~.0#bbcgcncnovc   AH#SSTXT_T_`gTpqHF^^'-d|GO$i &#YYZ^ZeZefmZvwH')$TWWs]VF^%CFa%adm%mp}%}~~.0#\\]a]h]hip]yzH#MMdkkZaNjkH!&#__`d`k`kls`|}H')$TWWs]VF^%CFa%adm%mp}%}~~.0#bbcgcncnovc   AH#SSTXT_T_`gTpqH &tGH M$($A$A&,Xvx|$}!M6 $&)%&6GFO??G@\] $&*&7&7&EGFO+$0DM$&)$&6GFOAA$++gB^_ ~~h3  v%GGr3  c                     U R                  5         U R                  U5      nU R                  US5      nU R                  U5      $ )aR  
fetch all the accounts associated with a profile

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
rY  )rA  spotPrivateGetV1AccountAccountsrK  parse_accountsr/  rM  rP  rY  s       r1  fetch_accountshtx.fetch_accounts_  sC     	77? x0""4((r3  c                     U R                  US5      nU R                  U R                  S0 5      nU R                  X2U5      nUU R                  US5      US S.$ )NrX  r  r=   )r@  r=   rX  code)rD  rK  r  )r/  accounttypeIdr  rX  s        r1  parse_accounthtx.parse_accountv  s_     !!'62t||^RH|V<""7D1	
 	
r3  r  c                    U R                  5       nU R                  USS5      nUb  U$ US:X  a  US:X  a  SnOUS:X  a  SnSnUb  U R                  U5      n[        S	[	        U5      5       Hx  nXX   n	U R                  U	S
5      n
U R                  U
SS5      nU R                  U	S5      nUS:X  a  X:X  a  U R                  U	S5      s  $ M_  X:X  d  Mf  U R                  U	S5      s  $    U R                  US	0 5      nU R                  US5      $ )a  
fetch all the accounts by a type and marginModeassociated with a profile

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

:param str type: 'spot', 'swap' or 'future
:param str [marginMode]: 'cross' or 'isolated'
:param str [symbol]: unified ccxt market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
	accountId
account-idNrM   r{  r  r|  rN   r   r@  subtyperX  r=   )load_accountssafe_value_2rv  rs  rt  rK  rD  )r/  rX  r  rb  rM  accountsr  rg  rx  r  r@  r  typeFromAccountdefaultAccounts                 r1  fetch_account_id_by_typehtx.fetch_account_id_by_type  s$    %%'%%fk<H	 6>W$%z)~~f-Hq#h-(AkG??7F3D&&tY=G"..w?Ox&++GT:: '(''66 ) 1b955r3  c                 h   U R                  U5      nU R                  US/ 5      n0 n0 U R                  S'   0 U R                  S'   [        S[	        U5      5       GH  nX5   nU R                  US5      nU R                  U5      nU R                  US5      n	U	S:H  n
0 U R                  S   U'   U R                  US/ 5      n0 n[        S[	        U5      5       GH  nX   nU R                  US	5      nU R                  US
S5      nXR                  S   U   U'   UU R                  S   U'   U R                  U5      nUUUU R                  US5      SS.U R                  US5      U R                  US5      S.S.SU R                  US5      S:H  U R                  US5      S:H  U R                  US5      U R                  U R                  U R                  US5      5      5      S.	UU'   GM     U R                  UUUU R                  US5      S:H  SSSSU
SSS.SSS.SSS.S.SUS.5      XH'   GM     U$ )z
fetches all available currencies on an exchange

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
rY  networkChainIdsByNamesnetworkNamesByChainIdsr   rT  	assetTypecryptochainschain	baseChaindisplayNameminDepositAmtNr  minWithdrawAmtmaxWithdrawAmt)depositr   depositStatusallowedwithdrawStatustransactFeeWithdrawwithdrawPrecision)	r@  r=   networkr  r  r  r   r_  r  
instStatusnormal)r  r   r  )r@  r  r=   r  r  r   r_  r>   rX  r  r  r"  )"spotPublicGetV2ReferenceCurrenciesr  r  rs  rt  rD  r  r  network_id_to_coderf  r.  r  safe_currency_structure)r/  rM  rP  rY  rw  rx  r4  
currencyIdr  r  rX  r  r"  r  
chainEntryuniqueChainIdtitlenetworkCodes                     r1  fetch_currencieshtx.fetch_currencies  s    ::6BJ ~~h313-.13-.q#d)$AGE))%<J**:6D((<I(D;=DLL1248^^E8R8FH1c&k*#Y
 $ 0 0W E**:{MRFS56t<UCHM56}E"55mD&'* $(#3#3J#P#'$
 $(#3#3J@P#Q#'#3#3J@P#Q%	 ##//
OLPYY $ 0 0=M NR[ [++J8MN!%!2!243G3GHXHXYcexHy3z!{%)% +6  77 **5,?8K   $#
  $#!
  $#  "$39 FLI %~ r3  	networkIdcurrencyCodec                   > [        U R                  S   R                  5       5      n[        U5      nUS:X  a  [	        U R
                  S-   5      eU R                  U R                  S   X5      n[        [        U ]'  U5      $ )Nr  r   z7 networkIdToCode() - markets need to be loaded at first)
r  r  r  rt  r%   r=   rK  r+  r9   r  )r/  r  r  r  
keysLengthnetworkTitler0  s         r1  r  htx.network_id_to_code!  sq    DLL!9:??ABY
?*c cddt||4L'MydS$2<@@r3  r  c                 t  > Uc  [        U R                  S-   5      e[        U R                  S   R	                  5       5      n[        U5      nUS:X  a  [        U R                  S-   5      eU R                  U R                  S   U0 5      nX;   a  XQ   $ [        [        U ]+  U5      nU R                  XVU5      $ )Nz3 networkCodeToId() requires a currencyCode argumentr  r   z7 networkCodeToId() - markets need to be loaded at first)r)   r=   r  r  r  rt  r%   rK  r+  r9   network_code_to_id)r/  r  r  r  r  uniqueNetworkIdsr  r0  s          r1  r  htx.network_code_to_id*  s    #DGG.c$cddDLL!9:??ABY
?*c cdd??4<<8P+QS_acd*#00 d>{KL??#3<PPr3  c                    U R                  5         SnU R                  SSU5      u  p!U R                  U R                  S0 5      nU R	                  USSS5      nU R                  USS/5      n0 nUS:H  nUS:H  nU R                  U R                  SS	S
5      nU R                  USS	U5      n	U R                  USS	U	5      n	U	S:H  n
U	S
:H  nSnU R                  SU5      u  pU R                  USS	/5      nUS:H  nUS:H  nUS:H  =(       d    U=(       a    U=(       d    UnSnU(       d  U(       a  U(       aK  U(       a"  U R                  U R                  XQ5      5      nGO3U R                  U R                  XQ5      5      nGOU R                  5         U R                  USSU5      nUUS'   U R                  U R                  XQ5      5      nOU(       a!  U R                  U R                  XQ5      5      nOU(       aI  U(       a!  U R                  U R                  XQ5      5      nOpU R!                  U R                  XQ5      5      nOOU
(       aH  U(       a!  U R#                  U R                  XQ5      5      nO U R%                  U R                  XQ5      5      nSU0nU R                  US5      nU(       d  U(       GaN  U(       a  ['        S[)        U5      5       H  nUU   nU R+                  U R-                  US5      5      nU R                  US5      n0 n['        S[)        U5      5       HA  nUU   nU R-                  US5      nU R/                  U5      nU R1                  UUU5      UU'   MC     U R3                  U5      UU'   M     U$ U R                  US/ 5      n['        S[)        U5      5       HA  nUU   nU R-                  US5      nU R/                  U5      nU R1                  UUU5      UU'   MC     U R3                  U5      n U$ U(       Ga#  ['        S[)        U5      5       GH  nUU   nU R-                  US5      nU R/                  U5      nU(       a  U R                  US0 5      n['        S[)        U5      5       HV  nUU   nU R-                  US5      n UU R5                  US5      S.n!U R+                  U 5      nU!UU'   U R3                  U5      nMX     M  U R7                  5       n"U R-                  US5      U"S'   U R-                  US5      U"S'   U"UU'   U R3                  U5      nGM
     U$ U(       Gap  U R                  US0 5      n#U(       a  ['        S[)        U5      5       H  nUU   nU R                  USS5      n U R9                  U 5      n$U R-                  US5      nU R;                  U5      n%U R-                  U$S U%S!   5      nUc  Mj  U R7                  5       n"U R-                  US"5      U"S'   U R-                  US5      U"S'   0 n&U"U&U'   U$S   nU R3                  U&5      UU'   M     U$ U R7                  5       n"U R-                  U#S#5      U"S'   U R-                  U#S"5      U"S$'   U R                  U#SS5      nU R/                  U5      nU"UU'   U R3                  U5      n U$ U
(       a  ['        S[)        U5      5       Hj  nUU   nU R-                  US5      nU R/                  U5      nU R7                  5       n"U R-                  US5      U"S'   U R-                  US5      U"S'   U"UU'   Ml     U R3                  U5      nU$ )%a  

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

query for balance and get the amount of funds available for trading or funds locked in orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.unified]: provide self parameter if you have a recent account with unified cross+isolated margin account
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nrj   isUnifiedAccountunifiedFrM   rP   r  r6  r   r   r|  r{  rN   r  r@  rY  r   rb  r  rT  margin_assetisolated_swapr  margin_available)r  freemargin_staticr  margin_frozenusedmargin_accountr  r  margin_balancewithdraw_availabletotal)rA  rB  rK  r  r  r  r  r  %spotPrivateGetV1MarginAccountsBalancerm  *spotPrivateGetV1CrossMarginAccountsBalancer  r  /spotPrivateGetV1AccountAccountsAccountIdBalance3contractPrivateGetLinearSwapApiV3UnifiedAccountInfo1contractPrivatePostLinearSwapApiV1SwapAccountInfo6contractPrivatePostLinearSwapApiV1SwapCrossAccountInfo+contractPrivatePostApiV1ContractAccountInfo+contractPrivatePostSwapApiV1SwapAccountInfors  rt  re  rD  r  parse_margin_balance_helpersafe_balancerf  r  r3  safe_currency)'r/  rM  rX  r  r  rn  rM   rP   r  r6  r   r   r  r|  r{  rN   rP  r  rw  rY  rx  r4  rb  balances	subResultr  balancer  r  marginAssetr  r  rg  
subBalancer  ro  r`  rT  accountsByCodes'                                          r1  fetch_balancehtx.fetch_balance8  s:     	99.$PVW//$,,C,,V5GTYZ6$6	#BC("++DLL:JIW_`$$W.>	>Z$$V-=y'Ri'X%
!??PVW
6$4i#@A*,w&("E(D%2C86#II$++V]JfgH#NNt{{[bOklH""$ 99$dFS	(1%OOPTP[P[\cPlmOOPTP[P[\cPlmHQQRVR]R]^eRnoVVW[WbWbcjWstKKDKKX_LhiKKDKKX_Lhi@ )x06q#d),A GE!--d.>.>uh.OPF#uf=H&(I"1c(m4"*1+%)%5%5gz%J
#66zB*.*J*J7TXZc*d	$	 5
 &*%6%6y%AF6N -b K  ??4<q#h-0A&qkG!%!1!1':!FJ22:>D#'#C#CGTSY#ZF4L	 1
 **62~ } 1c$i(Q"..unE#66{C$(OOE?B$OM"1c-&89"/"2#'#3#3G_#M$0$($4$4W>P$Q,
 "&!1!1(!;)3v!%!2!26!: : #llnG&*&6&6uo&NGFO&*&6&6uo&NGFO+2F<(!..v6F+ )z O OOD!R0Eq#d),A"1gG#11'?L\]H!--h7F!%!1!1'>!JJ#11*=H++FHhv>NOD '"&,,.*.*:*:7DT*U*.*:*:7O*T/1/6t,!'!1)-):):>)Jv# -H # ,,."&"2"25:N"O#'#3#3E;K#L !//~xP
..z:&t**62  1c$i(q'!--gx@
..z:,,."&"2"27<N"O"&"2"27O"L&t ) &&v.Fr3  c                 n   U R                  5         SnUb  U R                  U5      nSnU R                  SXC5      u  pS0 nSnUS:X  a]  U R                  US5      nUb"  U R	                  U R                  Xc5      5      nGOoXS'   U R                  U R                  Xc5      5      nGOIUc  [        U R                  S-   5      eU R                  USS5      nUc  XS'   OXS'   U R                  USS/5      nUS	   US
'   US   (       ak  Sn	U R                  SU5      u  pU	c  SOU	n	U	S:X  a!  U R                  U R                  Xc5      5      nOU	S:X  a   U R                  U R                  Xc5      5      nO~US   (       at  US:X  a)  US   US'   U R                  U R                  Xc5      5      nOEUS:X  a!  U R                  U R                  Xc5      5      nO[!        U R                  S-   U-   S-   5      eU R#                  US5      n
[%        U
[&        5      (       a  U R#                  U
S5      n
U R)                  U
5      $ )a&  
fetches information on an order made by the user

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

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   rM   clientOrderIdrH  z( fetchOrder() requires a symbol argumentclient_order_idrI  r=   r  r   r{  r|  r   rP   r  rb  rO   z fetchOrder() does not support r}  rY  r   )rA  r`  rB  rD  )spotPrivateGetV1OrderOrdersGetClientOrderrm  "spotPrivateGetV1OrderOrdersOrderIdr)   r=   r  r  r  /contractPrivatePostLinearSwapApiV1SwapOrderInfo4contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo)contractPrivatePostApiV1ContractOrderInfo)contractPrivatePostSwapApiV1SwapOrderInfor/   rK  r  r  parse_order)r/  r=   rb  rM  r`  rN  rn  rP  r   r  rV  s              r1  fetch_orderhtx.fetch_orderj  sO     	[[(F
!??f]

  ,,V_EM(  II$++V]Jfg&(
#BB4;;wC_`~'2\(\]] ..v7H/ZM$&(
#-:)*6,=+OP'-d|GO$h!
%)%G%GV\%]"
)3);W*
+#SSTXT_T_`gTpqH7*#XXY]YdYdelYuvH	")(.z(:GH%#MMdkkZaNjkH6)#MMdkkZaNjkH&tww1R'RU_'_bl'lmm| &1eT""OOE1-E&&r3  c                     S nX#;   a  X2   nOU R                  5       nUS   S:X  a  U R                  US5      US'   US   S:X  a  U R                  US5      US'   U$ )NrX  rD  r  r  frozenr  )r  rD  )r/  r  r  rw  r  s        r1  r  htx.parse_margin_balance_helper4  sg    >lGllnG6?g%"..w	BGFO6?h&"..w	BGFOr3  c                 ,   U R                  U R                  SS5      nUS:X  a  Uc  [        U R                  S-   5      eU R	                  5         S nSU0nUb  U R                  U5      nUS   US'   Ub  X8S'   U R                  US5      US	'   U R                  S	X5      u  pUb  XHS
'   S n	US:X  a!  U R                  U R                  X5      5      n	O U R                  U R                  X5      5      n	U R                  U	S/ 5      n
U R                  XX45      $ )Nr  r  z) fetchOrders() requires a symbol argumentstatesr=   rb  ru  i L
rv  rt  rY  )rD  r  r)   r=   rA  r`  r  r  spotPrivateGetV1OrderOrdersrm  spotPrivateGetV1OrderHistoryr  parse_orders)r/  r/  rb  ri  r  rM  methodr`  rn  rP  rY  s              r1  fetch_spot_orders_by_stateshtx.fetch_spot_orders_by_states@  s.   !!$,,0KMop77~'2](]^^ f
" [[(F &tGH$)L!"&((52E"FGJ22:wO#FO7777G8TUH88W9UVH6 ~~h3  u<<r3  c                 (    U R                  SXX45      $ )NzGpre-submitted,submitted,partial-filled,filled,partial-canceled,canceledr4  r/  rb  ri  r  rM  s        r1  fetch_spot_ordershtx.fetch_spot_orders  s(    //0y  |B  KP  Y  	Yr3  c                 (    U R                  SXX45      $ )Nz filled,partial-canceled,canceledr7  r8  s        r1  fetch_closed_spot_ordershtx.fetch_closed_spot_orders  s    //0RTZchqqr3  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSSS.nS nU R	                  USS5      nU R                  US5      n	U R                  USS	5      n
U R                  U/ S
Q5      nU(       d  U	(       d  U
(       a  Ub  X6S'   US   US'   SUS'   OUb  X&S'   US   US'   SUS'   U R                  SXd5      u  pdUS   (       Gac  S nU R                  SU5      u  pUc  SOUnUS:X  a  U(       a"  U R                  U R                  Xd5      5      nGOpU	(       a"  U R                  U R                  Xd5      5      nGOGU
(       a"  U R                  U R                  Xd5      5      nGOU R                  U R                  Xd5      5      nGOUS:X  a  U(       a"  U R                  U R                  Xd5      5      nGOU	(       a"  U R!                  U R                  Xd5      5      nGOU
(       a"  U R#                  U R                  Xd5      5      nGO{U R%                  U R                  Xd5      5      nGOYUS   (       GaN  US   (       a  U(       a"  U R'                  U R                  Xd5      5      nGOU	(       a!  U R)                  U R                  Xd5      5      nOU
(       a!  U R+                  U R                  Xd5      5      nOU R-                  U R                  Xd5      5      nOUS   (       a  US   US'   U(       a!  U R/                  U R                  Xd5      5      nOpU	(       a!  U R1                  U R                  Xd5      5      nOHU
(       a!  U R3                  U R                  Xd5      5      nO U R5                  U R                  Xd5      5      nU R                  US5      n[7        U[8        5      (       d  U R                  US/ 5      nU R;                  XX#5      $ ) Nz1 fetchContractOrders() requires a symbol argumentr   rR  )rw  r   stopr  stopLossTakeProfitr  Fr?  r@  r  r  rz  r=   r  r$  r  rx  r   r   rX  ry  r   fetchContractOrdersr{  r|  r   rO   rP   r  rb  rY  orders)r)   r=   rA  r`  safe_bool_2rK  r  r  r  r  6contractPrivatePostLinearSwapApiV1SwapTriggerHisordersrm  3contractPrivatePostLinearSwapApiV1SwapTpslHisorders4contractPrivatePostLinearSwapApiV1SwapTrackHisorders/contractPrivatePostLinearSwapApiV3SwapHisorders;contractPrivatePostLinearSwapApiV1SwapCrossTriggerHisorders8contractPrivatePostLinearSwapApiV1SwapCrossTpslHisorders9contractPrivatePostLinearSwapApiV1SwapCrossTrackHisorders4contractPrivatePostLinearSwapApiV3SwapCrossHisorders0contractPrivatePostSwapApiV1SwapTriggerHisorders-contractPrivatePostSwapApiV1SwapTpslHisorders.contractPrivatePostSwapApiV1SwapTrackHisorders)contractPrivatePostSwapApiV3SwapHisorders0contractPrivatePostApiV1ContractTriggerHisorders-contractPrivatePostApiV1ContractTpslHisorders.contractPrivatePostApiV1ContractTrackHisorders)contractPrivatePostApiV3ContractHisordersr  r  r2  )r/  rb  ri  r  rM  r`  rn  rP  r  r@  r  r  rC  s                r1  fetch_contract_ordershtx.fetch_contract_orders  s   >#DGG.a$abbV$ 	
 ""669=!__V5IJ>>&*e<6#XY(H ',$'-d|GO$%'GM" (-%"(,GJGFO22:wO(J!%!C!CDY[a!bJ%/%7jJZ'#ZZ[_[f[fgn[wxH'#WWX\XcXcdkXtuH#XXY]YdYdelYuvH#SSTXT_T_`gTpqHw&#__`d`k`kls`|}H'#\\]a]h]hip]yzH#]]^b^i^ijq^z{H#XXY]YdYdelYuvHIf~#TTUYU`U`ahUqrH'#QQRVR]R]^eRnoH#RRSWS^S^_fSopH#MMdkkZaNjkH!$*:$6!#TTUYU`U`ahUqrH'#QQRVR]R]^eRnoH#RRSWS^S^_fSopH#MMdkkZaNjkH^ 62&$''__VXr:F  >>r3  c           	      L    SS0nU R                  XX0R                  XT5      5      $ )Nr   z5,6,7)rU  rm  )r/  rb  ri  r  rM  rn  s         r1  fetch_closed_contract_orders htx.fetch_closed_contract_ordersf  s,    g
 ))&G@\]]r3  c                 B   U R                  5         SnUb  U R                  U5      nSnU R                  SXT5      u  pdUS:H  =(       d    US:H  nU(       a!  Uc  [        U R                  S-   U-   S-   5      eU(       a  U R                  XX45      $ U R                  XX45      $ )a  

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

fetches information on multiple orders made by the user
:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
:param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.trailing]: *contract only* set to True if you want to fetch trailing stop orders
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   rO   rP   z. fetchOrders() requires a symbol argument for  orders)rA  r`  rB  r)   r=   rU  r9  )r/  rb  ri  r  rM  r`  rN  r   s           r1  fetch_ordershtx.fetch_ordersl  s    * 	[[(F
!??v^
&(EjH.D#DGG.^$^ak$knw$wxx--fUKK))&GGr3  c                 2   U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4S5      $ SnUb  U R                  U5      nSnU R	                  SXd5      u  ptUS:X  a  U R                  XX45      $ U R                  XX45      $ )a  

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

fetches information on multiple closed orders made by the user
:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Frq   rs  rC   NrM   )rA  r  r  r`  rB  r<  rX  )r/  rb  ri  r  rM  rs  r`  rN  s           r1  fetch_closed_ordershtx.fetch_closed_orders  s    & 	88ATV`a445H&Y^hkll[[(F
!??@SU[d
00NN44VERRr3  c                 D	   U R                  5         SnUb  U R                  U5      n0 nSnU R                  SXT5      u  ptSnU R                  SXTS5      u  pSn	US:X  a  Ub  US   US'   U R	                  US5      n
U
ct  U R                  5         [        S[        U R                  5      5       HA  nU R                  U   nU R	                  US	5      S:X  d  M*  U R	                  US5      n
U
c  MA    O   XS'   Ub  X6S
'   U R                  US5      nU R                  U R                  Xd5      5      n	GO$Ub  US   US'   Ub  X6S'   U R                  USS5      nU R                  US5      nU R                  USS5      nU R                  U/ SQ5      nUS:X  Gad  SnU R                  SU5      u  nnUc  SOUnUS:X  a  U(       a"  U R!                  U R                  Xd5      5      n	GOrU(       a"  U R#                  U R                  Xd5      5      n	GOIU(       a"  U R%                  U R                  Xd5      5      n	GO U R'                  U R                  Xd5      5      n	GOUS:X  a  U(       a"  U R)                  U R                  Xd5      5      n	GOU(       a"  U R+                  U R                  Xd5      5      n	GOU(       a"  U R-                  U R                  Xd5      5      n	GO}U R/                  U R                  Xd5      5      n	GO[US:X  GaT  US:X  a  U(       a"  U R1                  U R                  Xd5      5      n	GO%U(       a!  U R3                  U R                  Xd5      5      n	OU(       a!  U R5                  U R                  Xd5      5      n	OU R7                  U R                  Xd5      5      n	OUS:X  a  U R	                  USS5      US'   U(       a!  U R9                  U R                  Xd5      5      n	OpU(       a!  U R;                  U R                  Xd5      5      n	OHU(       a!  U R=                  U R                  Xd5      5      n	O U R?                  U R                  Xd5      5      n	U R                  U	S5      n[A        U[B        5      (       d  U R                  US/ 5      nU RE                  UXRU5      $ )a  

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

fetch all unfilled currently open orders
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch open orders for
:param int [limit]: the maximum number of open order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
:param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
:param boolean [params.trailing]: *contract only* set to True if you want to fetch trailing stop orders
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r   rM   r=   rb  r  r   rX  rt  r  rz  r?  r  r@  r  FrA  r{  r|  r   rO   rP   r  usdtrY  rC  )#rA  r`  rB  r  rD  r  rs  rt  r  r  spotPrivateGetV1OrderOpenOrdersrm  rD  rK  r  r  7contractPrivatePostLinearSwapApiV1SwapTriggerOpenorders4contractPrivatePostLinearSwapApiV1SwapTpslOpenorders5contractPrivatePostLinearSwapApiV1SwapTrackOpenorders0contractPrivatePostLinearSwapApiV1SwapOpenorders<contractPrivatePostLinearSwapApiV1SwapCrossTriggerOpenorders9contractPrivatePostLinearSwapApiV1SwapCrossTpslOpenorders:contractPrivatePostLinearSwapApiV1SwapCrossTrackOpenorders5contractPrivatePostLinearSwapApiV1SwapCrossOpenorders1contractPrivatePostSwapApiV1SwapTriggerOpenorders.contractPrivatePostSwapApiV1SwapTpslOpenorders/contractPrivatePostSwapApiV1SwapTrackOpenorders*contractPrivatePostSwapApiV1SwapOpenorders1contractPrivatePostApiV1ContractTriggerOpenorders.contractPrivatePostApiV1ContractTpslOpenorders/contractPrivatePostApiV1ContractTrackOpenorders*contractPrivatePostApiV1ContractOpenordersr  r  r2  )r/  rb  ri  r  rM  r`  rn  rN  r6  rP  r  rx  r  r  r@  r  r  rC  s                     r1  fetch_open_ordershtx.fetch_open_orders  sh   " 	[[(F
!??@QSYb
99:KV]ef!$*4L!((>I ""$q#dmm"45A"mmA.G''8FB$($4$4Wd$C	$0! 6 %.L! "'YYv|4F;;DKK<XYH!+1$<( ',$&&vvyAG!%9M!N~~fj%@HYYv'\]F("!
%)%G%GHY[a%b"
F)3);W*
+#'#_#_`d`k`kls`|#}+#'#\#\]a]h]hip]y#z!#'#]#]^b^i^ijq^z#{#'#X#XY]YdYdelYu#v7*#'#d#deiepepqx  fB  $C+#'#a#abfbmbmnub~#!#'#b#bcgcncnovc  $A#'#]#]^b^i^ijq^z#{I%'#'#Y#YZ^ZeZefmZv#w+#'#V#VW[WbWbcjWs#t!#'#W#WX\XcXcdkXt#u#'#R#RSWS^S^_fSo#p8+(,(8(8V(TGH%#'#Y#YZ^ZeZefmZv#w+#'#V#VW[WbWbcjWs#t!#'#W#WX\XcXcdkXt#u#'#R#RSWS^S^_fSo#pr 62&$''__VXr:F  >>r3  r   c                 H    SSSSSSSSSSSSSSS.nU R                  X!U5      $ )Nr  canceledclosed	canceling)zpartial-filledzpartial-canceledfilledrw  	submittedr  r  23456711rD  r/  r   statusess      r1  parse_order_statushtx.parse_order_status  sJ     % *"!
$ &99r3  rV  c           	         U R                  USS5      nU R                  U R                  USS5      5      nUb  SnU R                  U/ SQ5      nU R                  US5      nU R                  US5      nS	U;   a  US	   R	                  S
5      nUS   nUS   nU R                  USS5      n	U R                  X5      nU R                  U/ SQ5      n
U R                  USS5      nS nS nUb(  UR                  S5      S:  a  U R                  US5      nO'U R                  USS5      nU R                  U/ SQ5      nU R                  U/ SQ5      nU R                  USS5      nU R                  USS5      nU R                  USU5      nS nUb>  S nU R                  US5      nUb  U R                  U5      nOUS:X  a  US   OUS    nUUS!.nU R                  US"5      nU R                  US#5      nU R                  US$5      nS nUb
  US:X  a  S%OS&nU R                  0 S'U_S(U_S)U_S*U
_S+U R                  U
5      _S,S _SUS   _S	U_S-S _S.S _S/U_SU_S0U R                  US1S25      _S3U_S4U_SU_S5U_S UUUUS6.EU5      $ )7Nerr_codeerr-coder  r   rejected)r=   order_id_strrH  r1  order_price_typerX  r  r   r   r  rb  )rG  rF  r  r!  client-order-idr`  field-cash-amountvolumer  )zfilled-cash-amountr  rN  )rL  zfield-amountrM  r  order_pricerO  z
field-feesr_  rQ  sellr  r  rS  trade_avg_pricer~  reduce_onlyFTr@  r=   r   r  rT  lastTradeTimestampr  postOnlyr2  r	  
stop-pricetrigger_pricer  r  rz  )	remainingr   
reduceOnlyr_  r~  )r  r  r[  rD  r  r3  safe_integer_nrZ  r  rK  r  
safe_orderr  )r/  rV  r`  rejectedCreateOrdersr   r=   r2  rX  	orderTyperg  r  r   r  r  rz  r  ra  r_  rc  rb  r  r~  reduceOnlyIntegerr  s                           r1  r(  htx.parse_order  s`   N  $11%ZP((););E7H)UV+F'IJ{3'9:U?f++C0IQ<DQ<D%%e_hG!!(3''/Z[	**52CE[\499X#6!#;##E+>?D''xBF%%e-jkD##E+\]""5'=A$$UM<H""5%9K ,,UK@M("55mD26&.fWovf~'C ""5*;<1 --e]C
(#4#9J  
E 
" 
 ] 
 	 

 Y/ 
 !$ 
 fX& 
 D 
 4 
  
 D 
 U 
 D..ulOT 
 w 
 D 
  f! 
" f# 
$ $- 
. / 	r3  r  c                     U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS'   U R	                  USSUSU5      $ )a  
create a market buy order by providing the symbol and cost

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

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
rM   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r`  buyN)rA  r`  r/   r=   create_order)r/  rb  r  rM  r`  s        r1  !create_market_buy_order_with_cost%htx.create_market_buy_order_with_cost  s`     	V$f~tww)ddee6;23  5$fMMr3  r2  r  r  trailingPercenttrailingTriggerPricec	                     Uc  [        U R                  S-   5      eUc  [        U R                  S-   5      eXhS'   XxS'   U R                  XX4XX5      $ )a*  
create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
:param str symbol: unified symbol of the market to create an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much you want to trade in units of the base currency, or number of contracts
:param float [price]: the price for the order to be filled at, in units of the quote currency, ignored in market orders
:param float trailingPercent: the percent to trail away from the current market price
:param float trailingTriggerPrice: the price to activate a trailing order, default uses the price argument
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
zA createTrailingPercentOrder() requires a trailingPercent argumentzF createTrailingPercentOrder() requires a trailingTriggerPrice argumentr  r  )r)   r=   r  )	r/  rb  rX  r2  r  r  r  r  rM  s	            r1  create_trailing_percent_order!htx.create_trailing_percent_order  sa     "#DGG.q$qrr'#DGG.v$vww$3 !)=%&  tUKKr3  c                    U R                  5         U R                  5         U R                  U5      nSnU R                  SU5      u  pU R	                  US   X5      n	U	US   S.n
UR                  SS5      nUR                  SS5      nU R                  U R                  US   0 5      nU R                  U/ S	Q5      nUc1  U R                  US
0 5      nX;   a  [        U R                  S-   5      eOrUS:X  a  SOSnU R                  USU5      nU R                  X5      U
S'   UU
S'   US:X  d  US:X  a  SU-   nO*US:w  a$  US:w  a  [        U R                  S-   U-   S-   5      eSnU R                  US:H  US:H  U5      u  nnU(       a  SnU R                  USS5      nUS:X  a  US-   nOUS:X  a  SnUS -   U-   U
S'   U R                  US!S"5      nUcF  U R                  U R                  S#0 5      nU R                  US5      nUU R!                  5       -   U
S"'   OUU
S"'   US$:X  a  S%U
S&'   OUS':X  a  S(U
S&'   OUS):X  a  S*U
S&'   US:X  a  US+:X  a  SnS,nU R#                  USS-S,5      u  nnU R%                  US.5      nU R'                  US.5      nUb  U R)                  UU5      nO}U(       ae  Uc  [+        U R                  S/-   5      eU R-                  U5      nU R-                  U5      nU R)                  U[.        R0                  " UU5      5      nOU R)                  X5      nUU
S0'   OU R)                  X5      U
S0'   U R                  US10 5      nUU;   a  U R                  X5      U
S2'   U R'                  U/ S3Q5      nU R3                  X5      $ )4a  
@ignore
       helper function to build request
       :param str symbol: unified symbol of the market to create an order in
       :param str type: 'market' or 'limit'
       :param str side: 'buy' or 'sell'
       :param float amount: how much you want to trade in units of the base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param str [params.timeInForce]: supports 'IOC' and 'FOK'
       :param float [params.cost]: the quote quantity that can be used alternative for the amount for market buy orders
       :returns dict: request to be sent to the exchange
       Nr_   rX  r=   )r  rb  zbuy- zsell-)r	  	stopPricer  r  z: createOrder() requires a triggerPrice for a trigger orderr  ltegteoperatorr  r  r  zstop-r  r  z  createOrder() does not support r[  r`  r  r  r  r  z-fokr  r  r  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 argumentr  r  r  )r	  r  r  r   r  r  r  )rA  r  r`  r  r  replacerK  r  r[  r)   r=   rD  price_to_precisionr/   handle_post_onlyr  uuidr  rf  r  amount_to_precisionr-   number_to_stringr7   
string_mulrm  )r/  rb  rX  r2  r  r  rM  r`  r  r  rn  r  r  r	  r  defaultOperatorstopOperatorr  r  r   r  brokerIdquoteAmountr  r  r_  r^  r  s                               r1  create_spot_order_requesthtx.create_spot_order_request  s    	V$
!??vV
11&.*U	 $Tl
 LL,	%%gr2	//$,,vC))&2]^!__W6FKN*'2n(noo + )-eUO++FJPL$($;$;F$QGL!".GJW$){*B#i/	|+)?O2O"477-O#ORV#VYb#bcc00h1F	UbHbdjk&%I&&v}eD%!F*IE!I*y0**6?DUV __T\\8R@F''5H)1DIIK)?G%&)6G%&  2GH:% ,GH5  0GH!K04-8<8U8UV\^k  nQ  SW  9X5-v##FF3DYYvv.F"66vtD2=&tww  2m  (m  n  n $(#8#8#@L"&"7"7">K"&":":67CUCUVbdoCp"qK"66vF +GH $ 8 8 HGH//'3DbI'#66vEGG6  $N  O{{7++r3  c                 F   U R                  U5      nUS   U R                  X5      US.nSn	U R                  US:H  US:H  U5      u  pU	(       a  SnU R                  USS5      n
U
S:X  a  S	nOU
S
:X  a  SnU R	                  U/ SQ5      nU R                  USS5      nU R                  USS5      nU R                  USS5      nU R                  USU5      nUSLnUSLnUSLnUSLnU(       aF  U R                  USSS5      nUUS'   U R                  X5      US'   Ub  U R                  X5      US'   GOU(       d  U(       ag  U(       a0  X(S'   U R                  X5      US'   Ub  U R                  X5      US'   OX(S'   U R                  X5      US'   Ub  U R                  X5      US'   OU(       aF  [        R                  " US5      nU R                  U5      US'   XS'   U R                  USS 5      US'   OZU R                  US!S"5      nUb  UUS!'   U R                  US"/5      nUS#:X  d  US:X  d  US	:X  d  US:X  a  U R                  X5      US$'   U R                  US%S&S'5      nU(       d6  U(       d/  U(       a  S(US&'   U R                  U/ S)QS(5      US*'   U(       d  X(S'   U R!                  US+S'5      nU(       a  U(       a  S,US-'   OS.US-'   U R#                  U R$                  S/0 5      nU R                  US5      nUUS0'   U R                  U/ S1Q5      nU R'                  X5      $ )2a  
@ignore
       helper function to build request
       :param str symbol: unified symbol of the market to create an order in
       :param str type: 'market' or 'limit'
       :param str side: 'buy' or 'sell'
       :param float amount: how much you want to trade in units of the base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param str [params.timeInForce]: supports 'IOC' and 'FOK'
       :param float [params.trailingPercent]: *contract only* the percent to trail away from the current market price
       :param float [params.trailingTriggerPrice]: *contract only* the price to trigger a trailing order, default uses the price argument
       :returns dict: request to be sent to the exchange
       r=   )r  r  r1  Nr`  	post_onlyr  r  r  fokr  r  r	  r  r  r  sl_trigger_pricer  tp_trigger_pricer  callback_rater  triggerTypetrigger_typeler  r  sl_order_price_typesl_order_pricetp_order_price_typetp_order_price100active_pricer  formula_pricer!  r   r  r  r  r  Fr   )	leverRate
lever_rater  r  r  r  offsetr  r  channel_code)r  r	  r  r  r  r  r  r  r  r  r  r  )r`  r  r  rD  safe_number_nsafe_number_2r  rf  r  r7   
string_divparse_to_numericr\  r  rD  r  r  rK  r  rm  )r/  rb  rX  r2  r  r  rM  r`  rn  r  r  r	  stopLossTriggerPricetakeProfitTriggerPricer  r  isTrailingPercentOrder	isTriggerisStopLossTriggerOrderisTakeProfitTriggerOrderr  trailingPercentStringr   r  r  r  r  s                              r1  create_contract_order_request!htx.create_contract_order_request   s    V$#D\..v>

 001A4;CVX^_D&&v}eD%DE!D))&2`a#11&/K]^!%!3!3F<MOa!b,,V5FX#//8NPUV!0!< ,	!5T!A#9#E ,,V]NTXYK&1GN#'+'>'>v'TGO$ )-)@)@)O&#'?%15-..2.E.Ef.c*+$040G0G0VG,-15-..2.E.Ef.e*+$040G0G0VG,-#$+$6$6$N!'+'<'<=R'SGO$&:N#*.*:*:6CUWf*gG&' //8I?[M(-:)*6O+<=w$%-45=DKDW#'#:#:6#I %%flM5Q
%.F)*&$($7$7@gij$kGL!).2*+%8$+!$*!x<##FD1"*6  $_  `{{7++r3  c                    U R                  5         U R                  U5      nU R                  U/ SQ5      nU R                  USS5      n	U R                  USS5      n
U R	                  US5      nUSLnUSLnU	SLnU
SLnSnUS   (       aE  U(       a  [        U R                  S	-   5      eU R                  XX4XV5      nU R                  U5      nGO*U R                  XX4XV5      nUS
   (       a  SnU R                  SU5      u  nnUc  SOUnUS:X  ah  U(       a  U R                  U5      nGOU(       d  U(       a  U R                  U5      nGOU(       a  U R                  U5      nGOU R                  U5      nGOUS:X  af  U(       a  U R                  U5      nGOaU(       d  U(       a  U R!                  U5      nGO@U(       a  U R#                  U5      nGO&U R%                  U5      nGOUS   (       Ga  U R'                  US5      nUc  [)        U R                  S-   5      eUS   (       ad  U(       a  U R+                  U5      nOU(       d  U(       a  U R-                  U5      nOU(       a  U R/                  U5      nOU R1                  U5      nOmUS   (       ac  U(       a  U R3                  U5      nOJU(       d  U(       a  U R5                  U5      nO*U(       a  U R7                  U5      nOU R9                  U5      nSnSnUS   (       aY  U R;                  0 SU_SU R'                  US5      _SS_SS_SS_SS_SS_SU_SU_SU_SU_SS_S S_S!S_S"S_S#S_S$S_S%S0EU5      $ U(       a'  U R=                  US0 5      nU R=                  US&0 5      nOAU(       a'  U R=                  US0 5      nU R=                  US'0 5      nOU R=                  US0 5      nU R?                  UU5      $ )(a  
create a trade order

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

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

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

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   rb  z; createOrders() requires all orders to have the same symbolrX  r2  r  r  rM  r`   zS createOrders() requires all orders to have the same margin mode(isolated or cross)rM   r  orders_datar   r{  r|  r   rO   rP   rY  successerrors)rA  rs  rt  rD  r*   r=   rK  r  r`  r  r  r  r  privatePostOrderBatchOrders0contractPrivatePostLinearSwapApiV1SwapBatchorder5contractPrivatePostLinearSwapApiV1SwapCrossBatchorder*contractPrivatePostSwapApiV1SwapBatchorder*contractPrivatePostApiV1ContractBatchorderr  r2  )r/  rC  rM  ordersRequestsrb  r`  r  rx  rawOrderrg  rX  r2  r  r  orderParamsmarginResultcurrentMarginModeorderRequestrn  rP  rw  rY  r  r  s                           r1  create_ordershtx.create_orders  s    	
q#f+&AyH''(;H~!%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAK==nkZL ,Q ,%!2J!%66(  4I  *I  J  J[[(FLf~#==hd\ao#AA(RV`es99\<@L!!,/9 ': &>77GH%3GM"h)3);W*
+#TTU\]H7*#YYZabH	"&>#NNwWHH%#NNwWHT &>__Xvr:F??8VR8DoodIr:G__T8R8F&&w7F  00r3  c                    U R                  5         SnUb  U R                  U5      nSnU R                  SXC5      u  pS0 nSnUS:X  av  U R                  USS5      nUc&  XS'   U R	                  U R                  Xc5      5      nGOXS'   U R                  USS/5      nU R                  U R                  Xc5      5      nGOUc  [        U R                  S-   5      eU R                  USS5      nUc  XS	'   OXS'   U R                  USS/5      nUS
   (       a	  US   US'   OUS   US'   U R                  USS5      n	U R                  US5      n
U R                  USS5      nU R                  U/ SQ5      nUS   (       Gac  SnU R                  SU5      u  pUc  SOUnUS:X  a  U	(       a"  U R                  U R                  Xc5      5      nGOU
(       a"  U R                  U R                  Xc5      5      nGO_U(       a"  U R!                  U R                  Xc5      5      nGO6U R#                  U R                  Xc5      5      nGOUS:X  a  U	(       a"  U R%                  U R                  Xc5      5      nGOU
(       a"  U R'                  U R                  Xc5      5      nGOU(       a"  U R)                  U R                  Xc5      5      nGOU R+                  U R                  Xc5      5      nGOqUS   (       GaH  US   (       a  U	(       a"  U R-                  U R                  Xc5      5      nGO3U
(       a"  U R/                  U R                  Xc5      5      nGO
U(       a!  U R1                  U R                  Xc5      5      nOU R3                  U R                  Xc5      5      nOUS
   (       a  U	(       a!  U R5                  U R                  Xc5      5      nOU
(       a!  U R7                  U R                  Xc5      5      nOgU(       a!  U R9                  U R                  Xc5      5      nO?U R;                  U R                  Xc5      5      nO[=        U R                  S-   U-   S-   5      eU R                  U R?                  Xt5      USS.5      $ )aF  
cancels an open order
:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.trigger]: *contract only* if the order is a trigger trigger order or not
:param boolean [params.stopLossTakeProfit]: *contract only* if the order is a stop-loss or take-profit order
:param boolean [params.trailing]: *contract only* set to True if you want to cancel a trailing order
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
NrW   rM   r  r   rH  z) cancelOrder() requires a symbol argumentr!  rI  rP   r  rb  r=   r  r?  r  r@  r  FrA  r   r{  r|  r   rO   z  cancelOrder() does not support r}  rw  )r=   r   ) rA  r`  rB  r  /spotPrivatePostV1OrderOrdersOrderIdSubmitcancelrm  r  3spotPrivatePostV1OrderOrdersSubmitCancelClientOrderr)   r=   rD  rK  r  r  3contractPrivatePostLinearSwapApiV1SwapTriggerCancel0contractPrivatePostLinearSwapApiV1SwapTpslCancel1contractPrivatePostLinearSwapApiV1SwapTrackCancel,contractPrivatePostLinearSwapApiV1SwapCancel8contractPrivatePostLinearSwapApiV1SwapCrossTriggerCancel5contractPrivatePostLinearSwapApiV1SwapCrossTpslCancel6contractPrivatePostLinearSwapApiV1SwapCrossTrackCancel1contractPrivatePostLinearSwapApiV1SwapCrossCancel-contractPrivatePostSwapApiV1SwapTriggerCancel*contractPrivatePostSwapApiV1SwapTpslCancel+contractPrivatePostSwapApiV1SwapTrackCancel&contractPrivatePostSwapApiV1SwapCancel-contractPrivatePostApiV1ContractTriggerCancel*contractPrivatePostApiV1ContractTpslCancel+contractPrivatePostApiV1ContractTrackCancel&contractPrivatePostApiV1ContractCancelr/   r(  )r/  r=   rb  rM  r`  rN  rn  rP  r   r  r@  r  r  s                r1  cancel_orderhtx.cancel_order  s8    	[[(F
!??v^

  ..v7H/ZM$&(
#OOPTP[P[\cPlm-:)*6,=+OPSSTXT_T_`gTpq~'2](]^^ ..v7H/ZM$&(
#-:)*6,=+OPh$*:$6!+1$<(&&vvyAG!%9M!N~~fj%@HYYv'\]Fh!
%)%G%GW]%^"
)3);W*
+#'#[#[\`\g\gho\x#y+#'#X#XY]YdYdelYu#v!#'#Y#YZ^ZeZefmZv#w#'#T#TUYU`U`ahUq#r7*#'#`#`aealalmta}#~+#'#]#]^b^i^ijq^z#{!#'#^#^_c_j_jkr_{#|#'#Y#YZ^ZeZefmZv#w	""&>#'#U#UVZVaVabiVr#s+#'#R#RSWS^S^_fSo#p!#'#S#STXT_T_`gTp#q#'#N#Nt{{[bOk#lH%#'#U#UVZVaVabiVr#s+#'#R#RSWS^S^_fSo#p!#'#S#STXT_T_`gTp#q#'#N#Nt{{[bOk#l"477-O#OR\#\_i#ijj( {{4++H= @
  	r3  idsc                    U R                  5         SnUb  U R                  U5      nSnU R                  SXC5      u  pS0 nSnUS:X  a  U R                  USS5      nU R                  USSU5      nUc!  [	        U[
        5      (       a  U/US'   O9XS'   O4[	        U[
        5      (       a  U/US'   OXS'   U R                  U/ S	Q5      nU R                  U R                  Xc5      5      nGO Uc  [        U R                  S
-   5      eU R                  USS5      nU R                  USSU5      nUc  SR                  U5      US'   OXS'   U R                  U/ SQ5      nUS   (       a	  US   US'   OUS   US'   U R                  USS5      n	U R                  US5      n
U R                  U/ SQ5      nUS   (       Ga  SnU R                  SU5      u  pUc  SOUnUS:X  at  U	(       a"  U R!                  U R                  Xc5      5      nGOU
(       a"  U R#                  U R                  Xc5      5      nGOU R%                  U R                  Xc5      5      nGOUS:X  ar  U	(       a"  U R'                  U R                  Xc5      5      nGOiU
(       a"  U R)                  U R                  Xc5      5      nGO@U R+                  U R                  Xc5      5      nGOUS   (       a  US   (       aq  U	(       a!  U R-                  U R                  Xc5      5      nOU
(       a!  U R/                  U R                  Xc5      5      nOU R1                  U R                  Xc5      5      nOUS   (       ap  U	(       a!  U R3                  U R                  Xc5      5      nOgU
(       a!  U R5                  U R                  Xc5      5      nO?U R7                  U R                  Xc5      5      nO[9        U R                  S-   U-   S-   5      eU R;                  US 5      nU R=                  U5      $ )!a  
cancel multiple orders
:param str[] ids: order ids
:param str symbol: unified market symbol, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: *contract only* if the orders are trigger trigger orders or not
:param bool [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NrX   rM   r  r   client-order-idsclientOrderIdsz	order-ids)r  r!  r   r"  z* cancelOrders() requires a symbol argumentr!  client_order_ids,rI  )r!  r#  r   r"  rP   r  rb  r=   r  r?  r  r@  )r?  r@  r  r   r{  r|  r   rO   z! cancelOrders() does not support r}  rY  )rA  r`  rB  r  r  strr  'spotPrivatePostV1OrderOrdersBatchcancelrm  r)   r=   r  joinrD  rK  r  r  r  r  r  r  r  r  r  r  r  r  r  r/   r  parse_cancel_orders)r/  r  rb  rM  r`  rN  rn  rP  r"  r  r@  r  rY  s                r1  cancel_ordershtx.cancel_orders  s    	[[(F
!??PV_
	
 !..v7H/ZN!..v7IK[]klN%nc22,/5GK(+.K(nc223A2BG./2@./6+uvCCDKKPWD`aH~'2^(^__!//8I?[N!//8JL\^lmN%&)hhsm
#-;)*6+uvh$*:$6!+1$<(&&vvyAG!%9M!NYYv'PQFh!
%)%G%GX^%_"
)3);W*
+#'#[#[\`\g\gho\x#y+#'#X#XY]YdYdelYu#v#'#T#TUYU`U`ahUq#r7*#'#`#`aealalmta}#~+#'#]#]^b^i^ijq^z#{#'#Y#YZ^ZeZefmZv#w	"&>#'#U#UVZVaVabiVr#s+#'#R#RSWS^S^_fSo#p#'#N#Nt{{[bOk#lH%#'#U#UVZVaVabiVr#s+#'#R#RSWS^S^_fSo#p#'#N#Nt{{[bOk#l"477-P#PS]#]`j#jkkh ~~h/''--r3  c                    U R                  US5      nS nUb  UR                  S5      nOU R                  US/ 5      nU R                  USS/ 5      n/ n[	        S[        U5      5       H+  nX6   nUR                  U R                  UUSS.5      5        M-     [	        S[        U5      5       HM  nXF   nUR                  U R                  UU R                  US	S
5      SU R                  US5      S.5      5        MO     U$ )N	successesr$  r  r  failedr   rw  )r@  r=   r   rH  rI  r  )r@  r=   r   r   )	rD  r  r  r   rs  rt  r  r  r  )r/  rC  r,  r  r-  rw  rx  rV  s           r1  r(  htx.parse_cancel_orders  s   : $$V[9	 ooc*GnnVY;G!!&(HbAq#g,'AJEMM$//$+   ( q#f+&AIEMM$//((
JG"!%!1!1%9J!K	+   ' r3  c                 6   U R                  5         SnUb  U R                  U5      nSnU R                  SX25      u  pB0 nSnUS:X  aQ  Ub  US   US'   U R                  U R	                  XR5      5      nU R                  US5      nU R                  SU05      /$ Uc  [        U R                  S-   5      eUS	   (       a  US
   US'   US   US'   U R                  USS5      nU R                  US5      n	U R                  USS5      n
U R                  U/ SQ5      nUS   (       Gac  SnU R                  SU5      u  pUc  SOUnUS:X  a  U(       a"  U R                  U R	                  XR5      5      nGOU	(       a"  U R                  U R	                  XR5      5      nGO_U
(       a"  U R!                  U R	                  XR5      5      nGO6U R#                  U R	                  XR5      5      nGOUS:X  a  U(       a"  U R%                  U R	                  XR5      5      nGOU	(       a"  U R'                  U R	                  XR5      5      nGOU
(       a"  U R)                  U R	                  XR5      5      nGOU R+                  U R	                  XR5      5      nGOqUS   (       GaH  US   (       a  U(       a"  U R-                  U R	                  XR5      5      nGO3U	(       a"  U R/                  U R	                  XR5      5      nGO
U
(       a!  U R1                  U R	                  XR5      5      nOU R3                  U R	                  XR5      5      nOUS	   (       a  U(       a!  U R5                  U R	                  XR5      5      nOU	(       a!  U R7                  U R	                  XR5      5      nOgU
(       a!  U R9                  U R	                  XR5      5      nO?U R;                  U R	                  XR5      5      nO[=        U R                  S-   U-   S-   5      eU R                  US5      nU R?                  U5      $ )aq  
cancel all open orders
:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.trigger]: *contract only* if the orders are trigger trigger orders or not
:param boolean [params.stopLossTakeProfit]: *contract only* if the orders are stop-loss or take-profit orders
:param boolean [params.trailing]: *contract only* set to True if you want to cancel all trailing orders
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NrU   rM   r=   rb  rY  r@  z- cancelAllOrders() requires a symbol argumentrP   r  r  r?  r  r@  r  FrA  r   r{  r|  r   rO   z$ cancelAllOrders() does not support r}  ) rA  r`  rB  1spotPrivatePostV1OrderOrdersBatchCancelOpenOrdersrm  r  r  r)   r=   rD  rK  r  r  r  6contractPrivatePostLinearSwapApiV1SwapTriggerCancelall3contractPrivatePostLinearSwapApiV1SwapTpslCancelall4contractPrivatePostLinearSwapApiV1SwapTrackCancelall/contractPrivatePostLinearSwapApiV1SwapCancelall;contractPrivatePostLinearSwapApiV1SwapCrossTriggerCancelall8contractPrivatePostLinearSwapApiV1SwapCrossTpslCancelall9contractPrivatePostLinearSwapApiV1SwapCrossTrackCancelall4contractPrivatePostLinearSwapApiV1SwapCrossCancelall0contractPrivatePostSwapApiV1SwapTriggerCancelall-contractPrivatePostSwapApiV1SwapTpslCancelall.contractPrivatePostSwapApiV1SwapTrackCancelall)contractPrivatePostSwapApiV1SwapCancelall0contractPrivatePostApiV1ContractTriggerCancelall-contractPrivatePostApiV1ContractTpslCancelall.contractPrivatePostApiV1ContractTrackCancelall)contractPrivatePostApiV1ContractCancelallr/   r(  )r/  rb  rM  r`  rN  rn  rP  rY  r  r@  r  r  s               r1  cancel_all_ordershtx.cancel_all_orders  s    	[[(F
!??@QSYb

 !$*4L!MMdkkZaNjkH >>(F3DD!   ~'2a(abbh$*:$6!'-d|GO$&&vvyAG!%9M!N~~fj%@HYYv'\]Fh!
%)%G%GHY[a%b"
)3);W*
+#'#^#^_c_j_jkr_{#|+#'#[#[\`\g\gho\x#y!#'#\#\]a]h]hip]y#z#'#W#WX\XcXcdkXt#u7*#'#c#cdhdodopw  eA  $B+#'#`#`aealalmta}#~!#'#a#abfbmbmnub~##'#\#\]a]h]hip]y#z	""&>#'#X#XY]YdYdelYu#v+#'#U#UVZVaVabiVr#s!#'#V#VW[WbWbcjWs#t#'#Q#QRVR]R]^eRn#oH%#'#X#XY]YdYdelYu#v+#'#U#UVZVaVabiVr#s!#'#V#VW[WbWbcjWs#t#'#Q#QRVR]R]^eRn#o"477-S#SV`#`cm#mnn >>(F3D++D11r3  r  c                     U R                  5         SUS:  a  U R                  US-  5      OS0nU R                  U R                  X25      5      nU$ )a4  
dead man's switch, cancel all orders after the given timeout

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

:param number timeout: time in milliseconds, 0 represents cancel the timer
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: the api result
r  r   r!  )rA  r  %v2PrivatePostAlgoOrdersCancelAllAfterrm  )r/  r  rM  rn  rP  s        r1  cancel_all_orders_afterhtx.cancel_all_orders_afterG  sU     	Wq[t((48q
 ==dkk'>Z[ r3  rT  c                 L   U R                  US5      nU R                  US5      nU R                  US5      nU R                  XR5      nU R                  XR5      nU R                  US5      nU R                  US5      nU R                  U5        UUUU R	                  U5      UUS.$ )Naddress
addressTagrT  noter  )rT  rH  tagr  rJ  r@  )rD  r  r  check_addressr  )	r/  depositAddressrT  rH  rK  r  r  rJ  r  s	            r1  parse_deposit_addresshtx.parse_deposit_addressb  s     "">9=~|<%%njA
%%j;&&z<7$$^W=	7#..y9"
 	
r3  r  c                    U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  XcS   /S5      nU R                  US5      $ )a  

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

fetch a dictionary of addresses for a currency, indexed by network
:param str code: unified currency code of the currency for the deposit address
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `address structures <https://docs.ccxt.com/#/?id=address-structure>` indexed by the network
rT  r=   rY  r  Fr  )rA  rT  %spotPrivateGetV2AccountDepositAddressrm  rK  parse_deposit_addressesindex_by)r/  r  rM  rT  rn  rP  rY  parseds           r1  "fetch_deposit_addresses_by_network&htx.fetch_deposit_addresses_by_network|  s     	==&
 ==dkk'>Z[ x4--df5E4FN}}VY//r3  c                     U R                  5         U R                  U5      nU R                  U5      u  pEU R                  X5      nU R	                  US   XF5      nXg   $ )ah  
fetch the deposit address for a currency associated with self account

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

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r  )rA  rT  handle_network_code_and_paramsrU  )select_network_code_from_unified_networks)r/  r  rM  rT  r  paramsOmitedindexedAddressesselectedNetworkCodes           r1  fetch_deposit_addresshtx.fetch_deposit_address  se     	==&$($G$G$O!BB4V"LLXV\M]_j}44r3  c                    U R                  5         U R                  U5      nSUS   0nU R                  U R                  Xd5      5      nU R	                  US/ 5      nU R                  XS   /S5      n	/ n
[        S[        U	5      5       HP  nX   nUS L =(       d    US   U:H  nUS L =(       d    US   U:H  nU(       d  M6  U(       d  M?  U
R                  U5        MR     U
$ )	NrT  r=   rY  r  Fr   rJ  r  )	rA  rT  &spotPrivateGetV2AccountWithdrawAddressrm  rK  rR  rs  rt  r  )r/  r  rJ  r  rM  rT  rn  rP  rY  allAddresses	addressesrx  rH  	noteMatchnetworkMatchs                  r1  fetch_withdraw_addresseshtx.fetch_withdraw_addresses  s    ==&
 >>t{{7?[\ x433DF;K:LeT	q#l+,A"oGC76?d+BI'4/WWY5G;5VLy\\  ) - r3  c                     Ub  US:  a  SnU R                  5         SnUb  U R                  U5      nSSSS.nUb  US   US'   Ub  X6S	'   U R                  U R                  Xd5      5      nU R	                  US
   XRU5      $ )a  

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

fetch all deposits made to an account
:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
NrC   r  nextr   rX  directr  r=   rT  rt  rY  rA  rT  $spotPrivateGetV1QueryDepositWithdrawrm  parse_transactionsr/  r  ri  r  rM  rT  rn  rP  s           r1  fetch_depositshtx.fetch_deposits  s     =ECKE}}T*H

 "*4.GJ#FO<<T[[=YZ6 &&x'7%PPr3  c                     Ub  US:  a  SnU R                  5         SnUb  U R                  U5      nSSSS.nUb  US   US'   Ub  X6S	'   U R                  U R                  Xd5      5      nU R	                  US
   XRU5      $ )a  
fetch all withdrawals made from an account

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

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch withdrawals for
:param int [limit]: the maximum number of withdrawals structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
NrC   r   rh  r   ri  r=   rT  rt  rY  rk  rn  s           r1  fetch_withdrawalshtx.fetch_withdrawals  s     =ECKE}}T*H

 "*4.GJ#FO<<T[[=YZ2 &&x'7%PPr3  transactionc                 `   U R                  US5      nU R                  U R                  US5      5      nU R                  US5      nUS:X  a  SnU R                  US5      nUb  [        R                  " U5      nU R                  US5      nU R                  US5      nUS	:X  a  UR                  S
5      S:  a  S
U-   nU R                  US5      n	U	S:H  n
0 SU_SU R                  USS5      _SU_SU_SU R                  U5      _SU R                  U5      _SU R                  US5      _SS _SS _SU R                  US5      _SS _SS _SU_SU R                  US5      _SU_SU R                  U R                  US5      5      _SU R                  US 5      _S U
UU R                  U5      S S!.S".E$ )#NrF  rT  rX  r   
withdrawalr_  r  ztx-hashr   0xr   zsub-typeFASTr@  r=   rY  txidr  rT  r  rH  	addressToaddressFromrK  zaddress-tagtagTotagFromr  r   r  r>  z
updated-at)rT  r  rate)commentinternalr_  )r  r  rD  r7   
string_absrZ  r  r  r  rf  parse_transaction_statusr.  )r/  rt  rT  r  r  rX  ra  r  txHashr6  r  s              r1  parse_transactionhtx.parse_transaction<  sD   f %%k<@	&&t'7'7Z'PQV4:D"";6((1G$$[':	!!+y9&++d"3a"7F]F"";
;f$
K
$$$[$?
 F
 	

 Y/
 t..y9
 t''Y?
 
 4
 4##K?
 T
 t
 D
 d&&{H=
 
  d33D4D4D[RY4Z[!
" t((lC#
$   ))'2)
 	
r3  c                     0 SS_SS_SS_SS_SS_S	S_S
S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_nU R                  X!U5      $ )Nunknownr-  
confirmingpending	confirmedr7  safeorphanr{  rw  	reexaminerejectpasszwallet-rejectzconfirm-errorrepealedzwallet-transferzpre-transfer	verifyingr  r  s      r1  r  htx.parse_transaction_status  s    
x
 )
 	

 D
 h
 
 

 
 h
 I
 X
 X
  !
" y#
$ I%
& '
* &99r3  rH  rK  c                 \   U R                  XE5      u  pEU R                  5         U R                  U5        U R                  U5      nUUS   R	                  5       S.nUb  XGS'   SnU R                  U5      u  pUb  U R                  X5      US'   [        U R                  XU5      5      nU R                  U R                  S0 5      n	U R                  U	SS5      (       Ga  U R                  US	5      n
U
c  U R                  5       nU R                  U R                  U R                   U5      5      U l        U R                  US
   U0 5      nU R                  US	5      n
U
c  [#        U R$                  S-   5      eU R                  XU5      nU R'                  US	5      nU R)                  U5      n[*        R,                  " X5      n[        U5      n[        U5      US	'   [        U R                  UUU5      5      nX'S'   U R/                  U R1                  Xu5      5      nU R3                  UU5      $ )a  

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

make a withdrawal
:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
r=   )rH  rT  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" parameterr  )handle_withdraw_tag_and_paramsrA  rL  rT  r  rX  r  floatcurrency_to_precisionrK  r  r  rf  r  map_to_safe_mapr*  
currenciesr)   r=   r  r  r7   
string_sub$spotPrivatePostV1DwWithdrawApiCreaterm  r  )r/  r  r  rH  rK  rM  rT  rn  r  withdrawOptionsr_  r  targetNetwork	feeStringr_  amountSubtractedStringamountSubtractedrP  s                     r1  r   htx.withdraw  s     99#F7#==& ,,.
 ?"%J"AA&I"#66{IGGt11$LM//$,,
BG>>/<??""651C{!224
"&"6"6t7G7GYc7d"e $0DkSU V&&}e<;+DGG  7Y  -Y  Z  Z224kJIYYvu-F008L%,%7%7%P"$%;<"9-GEN455d<LkZ[F"<<T[[=YZ %%h99r3  r   c           
      b    U R                  US5      nU R                  S U5      nUUS S US S S S S.	$ )NrY  )	r@  r=   r  rT  rT  r  fromAccount	toAccountr   )rD  r  )r/  r   rT  r=   r  s        r1  parse_transferhtx.parse_transfer  sM     h/&&tX6

 
	
r3  r  r  c                 z   U R                  5         U R                  U5      nUS   [        U R                  X5      5      S.nSnU R	                  SSU5      u  pU R                  U5      n	U R                  U5      n
U
S:H  nU	S:H  nU R                  XR                  5      nU R                  XR                  5      nU	S:H  nU
S:H  nU(       a(  U(       a!  [        U R                  S-   U-   S-   U-   5      eU	S	:H  =(       d    U
S	:H  nSnU(       aB  U	S
-   U
-   nU R                  USU5      nUUS'   U R                  U R                  Xu5      5      nGO[U(       a)  U(       a"  U R                  U R                  Xu5      5      nGO+U(       a(  U(       a!  U R                  U R                  Xu5      5      nOU(       a,  U(       a%  XS'   U R                  U R                  Xu5      5      nOU(       a,  U(       a%  XS'   U R!                  U R                  Xu5      5      nOUS:X  aT  U	S:X  d  US:X  a  Sn	OSn
U R                  US5      nU R#                  US5      nUb  U R%                  U5      nUUS'   OSUS'   U(       a  SOU	US'   U(       a  SOU
US'   U R'                  U R                  Xu5      5      nU R)                  UU5      $ )a  
transfer currency internally between wallets on the same account

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

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account to transfer from 'spot', 'future', 'swap'
:param str toAccount: account to transfer to 'spot', 'future', 'swap'
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.symbol]: used for isolated margin transfer
:param str [params.subType]: 'linear' or 'inverse', only used when transfering to/from swap accounts
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
r=   rT  r  Nr   r{  rJ   z+ transfer() cannot make a transfer between z and r  z-to-rX  rb  r   rO   zlinear-swapzmargin-accountr!  rM   r  r  )rA  rT  r  r  r  convert_type_to_accountin_arrayr  r*   r=   rD   spotPrivatePostV1FuturesTransferrm   privatePostCrossMarginTransferIn!privatePostCrossMarginTransferOutprivatePostDwTransferInMarginprivatePostDwTransferOutMarginr  rv  v2PrivatePostAccountTransferr  )r/  r  r  r  r  rM  rT  rn  r6  fromAccountIdtoAccountIdtoCross	fromCross
toIsolatedfromIsolatedfromSpottoSpotfromOrToFuturesAccountrP  rX  rb  s                        r1  r   htx.transfer  s   * 	==& D66tDE
 99*dFS44[A229=(!W,	]];9
}}]HH= E)%TWW'TTWbbelloxxyy"/9"<![+QZBZ! 6)K7D##FFD9D"GFO<<T[[=YZH'<<T[[=YZH6==dkk'>Z[H* +H99$++g:VWHf -H::4;;w;WXH("!V+1M$1M"/K))&(;684%!^^F3F06G,-06G,-(0fmGFO&,F+GDM88W9UVH ""8X66r3  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  U5      $ )aP  
fetch the borrow interest rates of all currencies

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `isolated borrow rate structures <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
rY  )rA  spotPrivateGetV1MarginLoanInforK  parse_isolated_borrow_ratesr  s       r1  fetch_isolated_borrow_rateshtx.fetch_isolated_borrow_ratesS  sE     	66v>< x4//55r3  r@  c           
         U R                  US5      nU R                  X25      nU R                  US/ 5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	UU R                  U5      U R	                  US5      U R                  U	5      U R	                  US5      SS S US.	$ )	Nrb  r  r   r   rT  zactual-ratei \&)	rb  r  baseRater  	quoteRater  r  rT  r@  )rD  re  rK  r  rf  )
r/  r@  r`  rg  rb  r  baseData	quoteDatar  r  s
             r1  parse_isolated_borrow_ratehtx.parse_isolated_borrow_rate~  s    0 ##D(3!!(3__T<<
??:q1OOJ2	!!(J7""9j9++F3((=A,,W5)))]C

 
	
r3  c                    Uc  [        U R                  S-   5      eSnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS	5	      $ U R	                  5         U R                  U5      nS
US   0nUb  X7S'   OS	US'   SnUS   (       a!  U R                  U R                  Xt5      5      nOCUS   (       a!  U R                  U R                  Xt5      5      nO[        U R                  S-   5      eU R                  US5      n	U R                  U	S5      n
U R                  U	S/ 5      n/ n[        S[        U5      5       Hv  nX   nXS'   U R                  US
5      nU R                  U5      nU R                  US5      nUR!                  UUU R#                  US5      UU R%                  U5      S.5        Mx     U R'                  US5      nU R)                  UUS   X#5      $ )af  

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

fetches historical funding rate prices
:param str symbol: unified symbol of the market to fetch the funding rate history for
:param int [since]: not used by huobi, but filtered internally by ccxt
:param int [limit]: not used by huobi, but filtered internally by ccxt
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
Nz5 fetchFundingRateHistory() requires a symbol argumentFr   rs  current_page
page_indexr   r   r  r=   rz  r   r   zA fetchFundingRateHistory() supports inverse and linear swaps onlyrY  r   funding_timefunding_rate)r@  rb  fundingRater  rT  r  rb  )r)   r=   r  fetch_paginated_call_cursorrA  r`  3contractPublicGetSwapApiV1SwapHistoricalFundingRaterm  9contractPublicGetLinearSwapApiV1SwapHistoricalFundingRater/   rK  rs  rt  rD  re  r  r  rf  r  r  r  )r/  rb  ri  r  rM  rs  r`  rn  rP  rY  cursorrw  ratesrx  r4  rg  symbolInnerr  sorteds                      r1  fetch_funding_rate_historyhtx.fetch_funding_rate_history  s    >#DGG.e$eff88AZ\fg334Mv^cm{  ~J  LM  OQ  R  RV$VD\
 #(K #%GK )OOPTP[P[\cPlmHHUUVZVaVabiVrsHtww)llmm. x0~6vr2q#f+&AIE$*.!''?H**84K))%@ILL%#//~F& LL3  ' e[1009I5XXr3  c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R                  " Xv5      nU R                  US5      n	U R                  X5      n
0 SU_SU
_SS _SS _S	S _S
S _SS _SS _SU R                  US5      _SU_SU R                  U5      _SU_SU_SU R                  U5      _SS _SS _SS _SU R                  U5      0E$ )Nestimated_rater  next_funding_timer  r@  rb  	markPrice
indexPriceinterestRateestimatedSettlePricer  rT  r  r  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)rf  r  rD  r7   r  re  r  parse_funding_interval)r/  r   r`  r  r  r  fundingTimeStringnextFundingTimeStringmillisecondsIntervalrg  rb  s              r1  parse_funding_ratehtx.parse_funding_rate  s     **85EF,,X~F#00;NO ,,X~F $ 0 0;N O&112G[##Ho>!!(3
H
f
 
 $	

 D
 #D
 
 
 4++HnE
  0
 t||,<=
 
 #$8
 "4<<0D#E
 "4
  '!
" &t#
$ 334HI%
 	
r3  c                 6    SSSSSS.nU R                  X!U5      $ )Nr   r   8h16h24h)360000014400000288000005760000086400000r  )r/  r  	intervalss      r1  r  htx.parse_funding_interval$  s-    
	 	X>>r3  c                 z   U R                  5         U R                  U5      nSUS   0nSnUS   (       a!  U R                  U R                  XB5      5      nOCUS   (       a!  U R	                  U R                  XB5      5      nO[        U R                  S-   5      eU R                  US0 5      nU R                  Xc5      $ )a  
fetch the current funding rate

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
r  r=   Nr   r   z: fetchFundingRate() supports inverse and linear swaps onlyrY  )	rA  r`  )contractPublicGetSwapApiV1SwapFundingRaterm  /contractPublicGetLinearSwapApiV1SwapFundingRater/   r=   rK  r  )r/  rb  rM  r`  rn  rP  rw  s          r1  fetch_funding_ratehtx.fetch_funding_rate.  s     	V$VD\
 )EEdkkRYFbcHHKKDKKX_LhiHtww)eeff  626&&v66r3  c                 6   U R                  5         U R                  U5      nU R                  U R                  SS5      nSnU R	                  USSU5      u  pBUb3  U R                  US5      nU R                  U5      nUS   nU(       a  SOSn0 nSn	US:X  a!  U R                  U R                  X5      5      n	O?US:X  a!  U R                  U R                  X5      5      n	O[        U R                  S-   5      eU R                  U	S	/ 5      n
U R                  X5      $ )
a  
fetch the funding rate for multiple markets

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

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexed by market symbols
r  r   Nr   r6  r   r   z1 fetchFundingRates() not support self market typerY  )rA  r  rD  r  r  r`  4contractPublicGetLinearSwapApiV1SwapBatchFundingRaterm  .contractPublicGetSwapApiV1SwapBatchFundingRater/   r=   rK  parse_funding_rates)r/  rk  rM  r  r6  firstSymbolr`  isLinearrn  rP  rY  s              r1  fetch_funding_rateshtx.fetch_funding_ratesW  s!    	%%g.))$,,8H(S77@SU^`no**7A6K[[-Fh'H"*h	G
 hPPQUQ\Q\]dQmnH	!JJ4;;W^KghHtww)\\]]& x4''66r3  c                    U R                  5         SnU R                  SU5      u  peUc  SOUn0 nUb  U R                  U5      US'   Ub  XGS'   SnSn	US:X  a=  Ub  U R                  U5      nUS   US'   U R	                  U R                  Xu5      5      n	O<Ub  U R                  U5      n
U
S   US	'   U R                  U R                  Xu5      5      n	U R                  U	S
5      nU R                  X5      nU R                  XX45      $ )a  
fetch the interest owed by the user for borrowing currency for margin trading

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

:param str code: unified currency code
:param str symbol: unified market symbol when fetch interest in isolated markets
:param int [since]: the earliest time in ms to fetch borrrow interest for
:param int [limit]: the maximum number of structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
Nrl   r{  z
start-datert  r|  r=   rb  rT  rY  )rA  r  yyyymmddr`  privateGetMarginLoanOrdersrm  rT  privateGetCrossMarginLoanOrdersrK  parse_borrow_interestsfilter_by_currency_since_limit)r/  r  rb  ri  r  rM  r  rn  r`  rP  rT  rY  interests                r1  fetch_borrow_interesthtx.fetch_borrow_interest  s     	
!??@UW]^
!+!3W*
$(MM%$8GL!#FO#!V,$*4L!66t{{77STH==.&.tn
#;;DKK<XYH. x0..t<2285PPr3  c                 r   U R                  US5      nUc  SOSnU R                  U5      nU R                  US5      nU R                  US5      nUUU R                  U R                  US5      5      U R	                  US5      U R	                  US5      U R	                  US5      UUU R                  U5      S	.	$ )
Nrb  r{  r|  z
accrued-atrT  zinterest-amountzinterest-ratezloan-amount)	r@  rb  rT  r	  r  amountBorrowedr  r  rT  )rD  r3  r  r  rf  r  )r/  r@  r`  rg  r  rb  r  s          r1  parse_borrow_interesthtx.parse_borrow_interest  s    T ##D(3!)!1W

!!(+!!&(3%%dL9	//0@0@z0RS((/@A ,,T?C"..t]C$"Y/

 
	
r3  c                 B    U R                  5       U R                  S   -
  $ )Nr  )millisecondsr  )r/  s    r1  r<  	htx.nonce  s       "T\\2B%CCCr3  r   r  c                 `
   SnU R                  X@R                  U5      5      n[        U[        5      (       Ga  US:X  d  US:X  a  XpR                  -  nOUS:X  d  US:X  a  US-  nUSU R                  X5      -   -  nUS:X  d  US:X  Ga$  U R                  5         U R                  U R                  5       S5      n	SS	U R                  U	S
.n
US:w  a  U R                  X5      n
U R                  U
5      nU R                  US5      nSR                  X0R                  X|/5      nU R                  U R!                  U5      U R!                  U R"                  5      [$        R&                  S5      nUSU R                  SU05      -   -  nUSU-   -  nUS:X  a  U R)                  U5      nSS0nO#SS0nOU(       a  USU R                  U5      -   -  nU R                  U R*                  S   U   SU R                  05      U-   nGO-U R-                  US5      nU R-                  US5      nU R-                  US5      nU R-                  US5      nS nU R/                  U R*                  S   U5      n[        U[        5      (       d<  U R/                  UU5      n[        U[        5      (       d  Ub  U R/                  UU5      nUnXpR                  X5      -  nUS:X  a   U(       a  USU R                  U5      -   -  nGOUS:X  Ga
  U R                  5         US:X  a  U R/                  U R0                  S0 5      nU R-                  USS5      nUR3                  S5      S :X  a1  UR5                  S!5      (       a  U R-                  US"5      nUc  UUS"'   OAUR5                  S#5      (       a+  U R-                  US$5      nUc  UU R7                  5       -   US$'   U R                  U R                  5       S5      n	SS	U R                  U	S
.n
U R                  U
5      n
US:w  a#  U R                  U5      nU R                  U
U5      n
U R                  U
S5      R9                  S%S&5      nSR                  UUX|/5      nU R                  U R!                  U5      U R!                  U R"                  5      [$        R&                  S5      nUSU R                  SU05      -   -  nUSU-   -  nUS:X  a'  U R)                  U5      n[;        U5      S:X  a  S'nSS0nOSS0nU R                  U R*                  S   U   SU05      U-   nXsXeS(.$ ))Nr  r   r   r   r   v2T
HmacSHA256r|  )SignatureMethodSignatureVersionAccessKeyId	TimestampPOSTT
base64&	Signature?zContent-Typezapplication/jsonz!application/x-www-form-urlencodedr   rI   r   r   r  r  r   r  r=   r  cancelrV  r  zorders/placer  z%2cz%2Cz{})r   r3  bodyheaders)r  extract_paramsr  r%  rG   implode_paramscheck_required_credentialsymdhmsr<  apiKeyrm  keysort	urlencoder'  rI   hmacencodesecrethashlibsha256r  r   rD  rK  r  rZ  endswithr  r  rt  )r/  pathr   r3  rM  r$  r#  r   queryr  rn  sortedRequestauthpayload	signaturerX  accesslevelOneNestedPathlevelTwoNestedPathrI   r   r  r=   channelCoder   sortedQuerys                             r1  signhtx.sign  s   		&"5"5d";<c3xSI%5||##);t3,,T:::Ci3+#5//1 KK

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

c:	'3(+#';;!*	! ,,w/V#"&,,u"5K"kk';?G~~gt4<<UEJ))VXs$AB IIdkk'&:DKK<TV]VdVdfno	dnnk9-EFFFsTz!V#99U+D4yA~#&(:G
 '(KG %%dii&6t&<H? C dOOr3  httpCodereasonr   r3  r$  r#  c
                 x   Uc  g SU;   a  U R                  US5      n
U
S:X  a  U R                  USS5      nU R                  S-   U-   nU R                  U R                  S   Xl5        U R                  U R                  S   X5        U R                  USS	5      nU R                  U R                  S   X5        [        U5      eS
U;   aC  U R                  S-   U-   nU R                  US
5      nU R                  U R                  S   X5        U R                  US5      nU R                  US5      nUb  U R                  US5      nU R                  US5      nU R                  US	5      nU R                  S-   U-   nU R                  U R                  S   UU5        U R                  U R                  S   UU5        g )Nr   errorr  r  r  r  r  zerr-msgerr_msgr  rY  r  r   )	rD  r  r=   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr%   r  r  )r/  r?  r@  r   r3  r$  r#  rP  requestHeadersrequestBodyr   r  feedbackmessagerY  
errorsListro  errcode
errmessagefeedBacks                       r1  handle_errorshtx.handle_errorst  s   x
 %%h9F ))(J
K77S=4/44T__W5Mt^44T__W5Mt^,,Xy)L44T__W5Mwa#H--Xww}t+H##Hf5D001I4Z~~h/^^D(3
!NN:q1E&&uj9G))%;Jww}t+H001I7T\]001I:W_`r3  c                 <   U R                  5         U R                  U5      nU R                  SXT5      u  pgSS0nUb  X(S'   Sn	US:X  a  US   US'   US	   (       aU  Sn
U R                  SU5      u  pU
c  S
OU
n
U
S:X  a	  US   US'   OUS   US'   U R	                  U R                  X5      5      n	OIU R                  U R                  X5      5      n	O(US   US'   U R                  U R                  X5      5      n	U R                  U	S/ 5      nU R                  XX#5      $ )aH  
fetch the history of funding payments paid and received on self account

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

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch funding history for
:param int [limit]: the maximum number of funding history structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
r}   rX  z30,31N
start_daterO   r=   r   r   r{  r|  mar_acctr  rb  rY  )
rA  r`  rB  r  :contractPrivatePostLinearSwapApiV3SwapFinancialRecordExactrm  4contractPrivatePostSwapApiV3SwapFinancialRecordExact4contractPrivatePostApiV3ContractFinancialRecordExactr  parse_incomes)r/  rb  ri  r  rM  r`  rN  r3  rn  rP  r  rY  s               r1  fetch_funding_historyhtx.fetch_funding_history  sO    	V$ >>?TV\e
G
 $)L!"(,GJh. "
%)%G%GH]_e%f"
)3);W*
+*0,GJ'*0*;GJ'ZZ[_[f[fgn[vw,  TTUYU`U`ahUpq &tGHPPQUQ\Q\]dQlmH~~h3!!$==r3  r  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nU R	                  SXC5      u  pVSU0nUS:X  a  US   (       a	  US   US'   OUS	   US
'   SnUS   (       a  Sn	U R                  SU5      u  pU	c  SOU	n	U	S:X  a"  U R                  U R                  Xv5      5      nU$ U	S:X  a"  U R                  U R                  Xv5      5      nU$ [        U R                  S-   5      eUS:X  a"  U R                  U R                  Xv5      5      nU$ US:X  a"  U R                  U R                  Xv5      5      nU$ [        U R                  S-   5      e)a  
set the level of leverage for a market

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

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nz) setLeverage() requires a symbol argumentr   r  rP   r   r  rb  r=   r  r   r{  r|  + setLeverage() not support self market typerO   )r)   r=   rA  r`  rB  r  5contractPrivatePostLinearSwapApiV1SwapSwitchLeverRaterm  :contractPrivatePostLinearSwapApiV1SwapCrossSwitchLeverRater/   /contractPrivatePostApiV1ContractSwitchLeverRate/contractPrivatePostSwapApiV1SwapSwitchLeverRate)
r/  r  rb  rM  r`  rN  r3  rn  rP  r  s
             r1  set_leveragehtx.set_leverage  s    >#DGG.Y$YZZV$ >>}f]
(
 !fY&7 &z 2GH'-d|GO$(J!%!C!CMSY!ZJ%/%7jJZ'UUVZVaVabiVqrN M w&ZZ[_[f[fgn[vwJ G #477-Z#Z[[ X%OOPTP[P[\cPkl* ) v%OOPTP[P[\cPkl& # #477-Z#Z[[r3  c                 .   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  USS5      nU R                  U5      n	UUU	UU R                  U5      UUS.$ )Nr  r  r9  r=   rb  asset)r@  rb  r  r  rT  r=   r  )rD  re  rf  r  r  r  r  )
r/  incomer`  rg  rb  r  r  r=   r  r  s
             r1  parse_incomehtx.parse_income2  s     ##FO<!!(3!!&(3%%fd3	fd+'''B
&&z2"Y/
 	
r3  positionc                    U R                  U R                  US5      5      nUS   nU R                  US5      nU R                  US5      nU R                  U5      nU R	                  US5      nU R                  US5      nU R                  US5      n	U	S:X  a  S	OS
n
U R	                  US5      nU R                  US5      nU R                  US5      n[
        R                  " U R                  US5      S5      nU R                  US5      n[
        R                  " XF5      nS nUS   (       a  [
        R                  " UU5      nO[
        R                  " UU5      nSn[
        R                  " UU5      nU R                  US5      nU R	                  US5      nU R                  US5      n[
        R                  " UU5      n[
        R                  " UU5      n[
        R                  " UU5      nU R                  0 SU_SS _SU_SU R                  U5      _SU_SU_SU R                  U5      _SU
_SU_SU R                  U5      _SU R                  U5      _SU_S U R                  U5      _S!S _S"S _S#U_S$U R                  U5      _U R                  U5      U R                  U5      U R                  U5      U R                  U5      S S S S S S S%.
E5      $ )&Nr  rb  r  r  	cost_openposition_marginr1  r  longshortprofit_unrealmargin_moder  profit_rater  
last_pricer   r{  r	  liquidation_priceadjust_factorr@  r=   	contracts
entryPrice
collateralr2  unrealizedPnlr  r   r  notionalr  	lastPriceliquidationPriceinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior  rT  r  lastUpdateTimestampr  r  )
r3  rD  rK  r  rf  r7   r  r  safe_positionr.  )r/  rf  r`  rb  rr  r  contractSizeStringrs  ry  rawSider2  unrealizedProfitr  r  r   rw  	faceValuerv  intialMarginPercentagert  rx  adjustmentFactorr|  r{  r}  s                            r1  parse_positionhtx.parse_positionN  sS   @ !!$"2"28_"MN!$$Xx8	v~>!22<@%%h<
((3DE""8[9!U*v++HoF%%h>
##Hl;''(8(8=(QSXY
$$X|<	&&yE	()))Y?H)))Y?H J!(!3!3M8!L%%h0@A
++H6IJ++HoF&-&8&89I8&T##../JHU(():JG!! #
H#
$#
 f#
 **95	#

 L#
 *#
 $++J7#
 D#
 -#
 ))(3#
 $++J7#
 *#
 ))(3#
 #
 #
   0!#
" T..}=##
$ (,'8'89O'P!%!2!23D!E+/+<+<=X+Y,,[9#'!#7#
  	r3  c           
         U R                  5         U R                  U5      nSnUb4  [        U5      nUS:  a#  U R                  US5      nU R	                  U5      nSnU R                  SUS5      u  pbSnU R                  SX2S5      u  prSnU R                  SX25      u  pUS:X  a  SnSn	US:X  aH  US:X  a  U R                  U5      n	OxUS:X  a  U R                  U5      n	O`[        U R                  S	-   5      eUS:X  a  U R                  U5      n	O0US
:X  a  U R                  U5      n	O[        U R                  S	-   5      eU R                  U	S/ 5      n
U R                  U	S5      n/ n[!        S[        U
5      5       HK  nX   nU R#                  U5      nUR%                  U R'                  UUU R)                  U5      S.5      5        MM     U R+                  USUS5      $ )a  
fetch all open positions

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

:param str[] [symbols]: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.subType]: 'linear' or 'inverse'
:param str [params.type]: *inverse only* 'future', or 'swap'
:param str [params.marginMode]: *linear only* 'cross' or 'isolated'
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr   r   r{  r   rM   rP   r|  z. fetchPositions() not support self market typerO   rY  r9  r  rT  rb  F)rA  r  rt  rD  r`  r  r  rB  2contractPrivatePostLinearSwapApiV1SwapPositionInfo7contractPrivatePostLinearSwapApiV1SwapCrossPositionInfor/   r=   ,contractPrivatePostApiV1ContractPositionInfo,contractPrivatePostSwapApiV1SwapPositionInforK  r  rs  r  r  rm  r  filter_by_array_positions)r/  rk  rM  r`  symbolsLengthro  r  r6  rN  rP  rY  r  rw  rx  rf  rT  s                   r1  fetch_positionshtx.fetch_positions  s     	%%g.LMq ((!4U+
!??@PRXZab
99:JF\de
!??@PRXa
!JhZ'RRSYZw&WWX^_"477-]#]^^: X%LLVTv%LLVT"477-]#]^^f x4%%h5	q#d)$AwH((2FMM$++f& LL3/   % --fhOOr3  c                    U R                  5         U R                  U5      nSnU R                  SU5      u  pBUc  SOUnU R                  SX25      u  pV0 nUS   (       a  US   (       a	  US   US'   OUS:X  a  SUS	'   US
   US'   SnUS   (       af  US:X  a!  U R	                  U R                  Xv5      5      nOUS:X  a!  U R                  U R                  Xv5      5      nO~[        U R                  S-   5      eUS:X  a!  U R                  U R                  Xv5      5      nO?US:X  a!  U R                  U R                  Xv5      5      nO[        U R                  S-   5      eU R                  US5      n	Sn
US:X  a  U	n
OU R                  U	S5      n
U R                  U
S/5      nU R                  U
S5      nSnUS   (       a;  US   (       a1  [        S[        U5      5       H  nX   nUS   US
   :X  d  M  Un  O   OU R                  US5      nU R                  US5      nU R!                  U R                  X5      5      nUUS'   U R#                  U5      US'   U$ )a|  
fetch data on a single open contract trade position

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

:param str symbol: unified market symbol of the market the position is held in, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr   r{  rP   r   r  rb  r!  r  r=   r  r   r|  z- fetchPosition() not support self market typerO   rZ  rY  r   	positionsr9  r  rT  )rA  r`  r  rB  9contractPrivatePostLinearSwapApiV1SwapAccountPositionInform  >contractPrivatePostLinearSwapApiV1SwapCrossAccountPositionInfor/   r=   3contractPrivatePostApiV1ContractAccountPositionInfo3contractPrivatePostSwapApiV1SwapAccountPositionInforK  r  rs  rt  r  r  r  )r/  rb  rM  r`  r  rN  r3  rn  rP  rY  r  omittedr  rf  rx  r4  r  rT  s                     r1  fetch_positionhtx.fetch_position0  sl    	V$
!??QWX
!+!3W*
 >>PV_
(y 1 &z 2GHW$,2()'-d|GO$(Z'YYZ^ZeZefmZuvw&^^_c_j_jkr_z{"477-\#\]]n X%SSTXT_T_`gTopv%SSTXT_T_`gTop"477-Z#Z[[L x0 GoodA.G))Gk]3OOG[9	(y 11c)n-!)VD\9$H	 . y!4H%%h5	$$T[[%CD'{!\\)4zr3  c                 H    SSSSSSSSSSSSSSS	.nU R                  X!U5      $ )
NrD  r_  r   creditr  rv  exchangerebate)rD  etfztransact-feezfee-deductionr   r  liquidationr	  r  r   zwithdraw-feer  zother-typesr  r  )r/  rX  r  s      r1  parse_ledger_entry_typehtx.parse_ledger_entry_type*  sH    !"""  $!"%
  T22r3  itemc                    U R                  US5      nU R                  X25      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  UUU R                  US5      UUUU R                  U5      UU R                  US5      UU R                  U5      S S S S S.U5      $ )	NrT  
transactIdtransferTypetransactTimer  r1  transactAmt)r@  r=   r1  r  referenceIdreferenceAccountrX  rT  r  r  rT  beforeafterr   r_  )rD  r  r  r  safe_ledger_entryr  rf  r  )	r/  r  rT  r  r  r=   r  r  r  s	            r1  parse_ledger_entryhtx.parse_ledger_entry=  s     %%dJ7
&&z<%%j;dL1''n=%%dN;	""45%%))$< '00>&&t];"Y/'
  ! 	r3  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4S5      $ U R                  SSSU5      nSU0nSnUb  U R	                  U5      nUS   US	'   Ub  X'S
'   Ub  X7S'   U R                  SXt5      u  ptU R                  U R                  Xt5      5      n	U R                  U	S/ 5      n
U R                  XX#5      $ )aL  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

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

:param str [code]: unified currency code, default is None
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
:param int [limit]: max number of ledger entries to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
Fr   rs  r  rM   Nr  r=   rT  	startTimer  endTimerY  )
rA  r  r  r  rT  r  spotPrivateGetV2AccountLedgerrm  rK  parse_ledger)r/  r  ri  r  rM  rs  r  rn  rT  rP  rY  s              r1  fetch_ledgerhtx.fetch_ledgerd  s    	88PZ[44]DQV`cdd11&$fM		
 }}T*H"*4.GJ#(K $G229gN55dkk'6RSB x4  >>r3  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  XAS5      $ )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
rY  r  )rA  0contractPublicGetLinearSwapApiV1SwapAdjustfactorr  parse_leverage_tiers)r/  rk  rM  rP  rY  s        r1  fetch_leverage_tiershtx.fetch_leverage_tiers  sG     	HHP< ~~h3((HHr3  c                    U R                  US5      nU R                  US5      n/ nU R                  US/ 5      n[        S[        U5      5       H  nXg   nU R                  US5      n	U R                  US/ 5      n
[        S[        U
5      5       H  nX   nU R                  US5      nUR	                  U R                  US5      U R                  XBS S	5      U R                  U5      U R                  US
5      U R                  US5      U R                  [        R                  " X5      5      U R                  U	5      US.5        M     M     U$ )Ntrade_partitionr  r  r   r  laddersrq  ladderrO   min_sizemax_size)tierrb  rT  minNotionalmaxNotionalmaintenanceMarginRatemaxLeverager@  )rD  r  rs  rt  r  r  re  r  rf  r.  r7   r  )r/  r@  r`  r  rg  tiersbracketsrx  r  r  r  kbracketadjustFactors                 r1  parse_market_leverage_tiershtx.parse_market_leverage_tiers  s?   %%d,=>
##D/:>>$3q#h-(A;D''l;HnnT9b9G1c'l+!*#//I --gx@"..xvN $ 7 7
 C#'#3#3GZ#H#'#3#3GZ#H-1->->w?Q?QR^?i-j#'#4#4X#>#	 	 ,	 )" r3  r   c                    US:w  a*  US:w  a$  US:w  a  US:w  a  [        U R                  S-   5      eU R                  5         SSSS	S
.nU R                  U5      nU R	                  USSS5      nXb   US.n	Ub  XIS'   Sn
US   (       aA  U R                  US   S5      U	S'   US   U	S'   U R                  U R                  X5      5      n
OhUS   (       a6  SU	S'   US   U	S'   US   U	S'   U R                  U R                  X5      5      n
O(US   U	S'   U R                  U R                  X5      5      n
U R                  U
S5      nU R                  US5      nU R                  XX45      $ )uH  
Retrieves the open interest history of a currency

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

:param str symbol: Unified CCXT market symbol
:param str timeframe: '1h', '4h', '12h', or '1d'
:param int [since]: Not used by huobi api, but response parsed by CCXT
:param int [limit]: Default：48，Data Range [1,200]
:param dict [params]: Exchange specific parameters
:param int [params.amount_type]: *required* Open interest unit. 1-cont，2-cryptocurrency
:param int [params.pair]: eg BTC-USDT *Only for USDT-M*
:returns dict: an array of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
r   r   12hr   zJ fetchOpenInterestHistory cannot only use the 1h, 4h, 12h and 1d timeframer   r   12hourr   )r   r   r  r   amount_type
amountTyper  )r  r  Nrt  rP   r@  r  r  rb  r   rO   r=   r  rY  r  )r*   r=   rA  r`  r\  rD  -contractPublicGetApiV1ContractHisOpenInterestrm  3contractPublicGetLinearSwapApiV1SwapHisOpenInterest-contractPublicGetSwapApiV1SwapHisOpenInterestrK  r  parse_open_interests_history)r/  rb  r  ri  r  rM  r   r`  r  rn  rP  rY  r  s                r1  fetch_open_interest_historyhtx.fetch_open_interest_history  s   " d!2yE7Ii[_N_TWW'sstt	

 V$((aP
 +%
 #FO('+'7'7v'XGO$ &x 0GHII$++V]JfgHH'-GO$'-d|GO$'-d|GO$OOPTP[P[\cPlmH'-d|GO$II$++V]JfgHz x0~~dF+00uLLr3  c                 F   U R                  5         U R                  U5      nSnUb4  [        U5      nUS:  a#  U R                  US5      nU R	                  U5      n0 nSnU R                  SX2S5      u  prSnU R                  SX25      u  pSn	US:X  a!  U R                  U R                  Xb5      5      n	OLUS:X  a!  U R                  U R                  Xb5      5      n	O%SUS'   U R                  U R                  Xb5      5      n	U R                  U	S	/ 5      n
U R                  X5      $ )
a  
Retrieves the open interest for a list of symbols

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

:param str[] [symbols]: a list of unified CCXT market symbols
:param dict [params]: exchange specific parameters
:returns dict[]: a list of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
Nr   r   r   rP   r   rO   r  rY  )rA  r  rt  rD  r`  r  rB  *contractPublicGetApiV1ContractOpenInterestrm  *contractPublicGetSwapApiV1SwapOpenInterest0contractPublicGetLinearSwapApiV1SwapOpenInterestr  parse_open_interests)r/  rk  rM  r`  r  ro  rn  r6  rN  rP  rY  s              r1  fetch_open_interestshtx.fetch_open_interestsb  s0    	%%g.LMq ((!4U+99:JF\de
!??@PRXa
!FFt{{SZGcdH& 	!FFt{{SZGcdH& (.GO$LLT[[Y`MijH. ~~h3((77r3  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eUS   (       a  [	        U R                  S-   5      eSUS   0nSnUS   (       aA  U R                  US	   S
5      US
'   US   US'   U R                  U R                  XB5      5      nOPUS   (       a&  SUS
'   U R                  U R                  XB5      5      nO U R                  U R                  XB5      5      nU R                  US/ 5      nU R                  US   U5      nU R                  US5      nXS'   U R                  U5      US'   U$ )a  
Retrieves the open interest of a currency

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

:param str symbol: Unified CCXT market symbol
:param dict [params]: exchange specific parameters
:returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
r   z3 fetchOpenInterest() supports contract markets onlyrQ   z> fetchOpenInterest() does not currently support option marketsr  r=   NrP   r@  r  r  rb  r   rO   rY  r   r9  r  rT  )rA  r`  r*   r=   r/   rD  r  rm  r  r  rK  parse_open_interestr  r  )	r/  rb  rM  r`  rn  rP  rY  openInterestr  s	            r1  fetch_open_interesthtx.fetch_open_interest  sa    	V$j!TWW'\\]](tww)iijjVD\
 ('+'7'7v'XGO$ &x 0GHFFt{{SZGcdHH'-GO$LLT[[Y`MijH FFt{{SZGcdH| x4//Q@%%h5	$-[!#'<<	#:Z r3  c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U R	                  Xb5      UUUUUU R                  U5      US.U5      $ )Nr9  r  valuer  )rb  r	  r
  openInterestAmountopenInterestValuer  rT  r@  )r  rf  rD  safe_open_interestre  r  )r/  r	  r`  r  r  r  rg  s          r1  r  htx.parse_open_interest%   s    j %%h5	!!(H5  73##Ho>&&&&x8  "(!&"Y/	(
 	 		r3  c                 (   U R                  5         U R                  U5      nU R                  U5      nUS   U R                  X#5      US   S.nU R	                  U R                  Xt5      5      nU R                  X5      n	U R                  U	UUS.5      $ )a  
create a loan to borrow margin

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

:param str symbol: unified market symbol, required for isolated margin
:param str code: unified currency code of the currency to borrow
:param float amount: the amount to borrow
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
r=   )rT  r  rb  r  rb  )rA  rT  r`  r  privatePostMarginOrdersrm  parse_margin_loan)
r/  rb  r  r  rM  rT  r`  rn  rP  rt  s
             r1  borrow_isolated_marginhtx.borrow_isolated_margini   s     	==&V$ 00>Tl

 //G0LM ,,X@{{;)
  	r3  c                     U R                  5         U R                  U5      nUS   U R                  X5      S.nU R                  U R	                  XS5      5      nU R                  Xd5      nU R	                  USU05      $ )a  
create a loan to borrow margin

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

:param str code: unified currency code of the currency to borrow
:param float amount: the amount to borrow
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
r=   r  r  )rA  rT  r  privatePostCrossMarginOrdersrm  r  )r/  r  r  rM  rT  rn  rP  rt  s           r1  borrow_cross_marginhtx.borrow_cross_margin   s     	==& 00>
 44T[[5QR ,,X@{{;f)
  	r3  c                 p   U R                  5         U R                  U5      nU R                  SSX5      nUS   U R                  X#5      US.nU R	                  U R                  Xt5      5      nU R                  US/ 5      n	U R                  U	S5      n
U R                  X5      nU R                  UUUS.5      $ )a  
repay borrowed margin and interest

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

:param str symbol: unified market symbol
:param str code: unified currency code of the currency to repay
:param float amount: the amount to repay
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
rM   r|  r=   rT  r  r  Datar   r  rA  rT  r  r  v2PrivatePostAccountRepaymentrm  rK  r  )r/  rb  r  r  rM  rT  r  rn  rP  rY  loanrt  s               r1  repay_isolated_marginhtx.repay_isolated_margin   s     	==&11&*fU	 00>"

 55dkk'6RS x4tQ',,T<{{;)
  	r3  c                 p   U R                  5         U R                  U5      nU R                  SSSU5      nUS   U R                  X5      US.nU R	                  U R                  Xc5      5      nU R                  US/ 5      nU R                  US5      n	U R                  X5      n
U R                  U
SU05      $ )	a  
repay borrowed margin and interest

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

:param str code: unified currency code of the currency to repay
:param float amount: the amount to repay
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
rM   r{  Nr=   r  r  r   r  r  )r/  r  r  rM  rT  r  rn  rP  rY  r  rt  s              r1  repay_cross_marginhtx.repay_cross_margin   s     	==&11&'4P	 00>"

 55dkk'6RS x4tQ',,T<{{;f)
  	r3  c                     U R                  US5      nU R                  USS5      U R                  S U5      S S UU R                  U5      US.$ )N	repayTimerepayIdrY  )r=   rT  r  rb  r  rT  r@  )r  r  r  r  )r/  r@  rT  r  s       r1  r  htx.parse_margin_loan   sZ    , %%dK8	$$T9f=//h?"Y/
 	
r3  c                    Uc  [        U R                  S-   5      eU R                  US5      nU R                  US/5      nU R	                  U5      n0 nUS   (       a	  US   US'   OUS   US'   Ub  X'S	'   Ub  X7S
'   Ub  XWS'   SnUS   (       aL  US   (       a!  U R                  U R                  Xt5      5      nOAU R                  U R                  Xt5      5      nO U R                  U R                  Xt5      5      nU R                  US5      n	U R                  U	S5      n
U R                  X5      nU R                  US5      $ )u+  
Fetches historical settlement records

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

:param str symbol: unified symbol of the market to fetch the settlement history for
:param int [since]: timestamp in ms, value range = current time - 90 days，default = current time - 90 days
:param int [limit]: page items, default 20, shall not exceed 50
:param dict [params]: exchange specific params
:param int [params.until]: timestamp in ms, value range = start_time -> current time，default = current time
:param int [params.page_index]: page index, default page 1 if not filled
:param int [params.code]: unified currency code, can be used when symbol is None
:returns dict[]: a list of `settlement history objects <https://docs.ccxt.com/#/?id=settlement-history-structure>`
Nz4 fetchSettlementHistory() requires a symbol argumentr  rP   r  rb  r=   r  start_atrz  end_atrO   r   rY  settlement_recordr  )r)   r=   r  r  r`  5contractPublicGetLinearSwapApiV1SwapSettlementRecordsrm  /contractPublicGetSwapApiV1SwapSettlementRecords/contractPublicGetApiV1ContractSettlementRecordsrK  parse_settlementsr  )r/  rb  ri  r  rM  r  r`  rn  rP  rY  settlementRecordsettlementss               r1  fetch_settlement_historyhtx.fetch_settlement_history!  sS   " >#DGG.d$dee!!&'26G9-V$( &x 0GH'-d|GO$"'J#(K  %H&>hUUVZVaVabiVrsOOPTP[P[\cPlmKKDKKX_LhiHj x0??41DE,,-=F||K55r3  codesc                     U R                  5         U R                  U5      nU R                  US5      nU R                  XAS5      $ )aM  
fetch deposit and withdraw fees

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

:param str[]|None codes: list of unified currency codes
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `fees structures <https://docs.ccxt.com/#/?id=fee-structure>`
rY  rT  )rA  r  r  parse_deposit_withdraw_fees)r/  r  rM  rP  rY  s        r1  fetch_deposit_withdraw_feeshtx.fetch_deposit_withdraw_fees}!  sF     	::6BJ ~~h///ZHHr3  c                    U R                  US/ 5      nU R                  U5      n[        S[        U5      5       H  nX5   nU R	                  US5      nU R	                  US5      nU R                  U5      n	S n
S nUS:X  a  U R                  US5      n
U
SS.nOU R                  US	5      n
U
S
S.nUS S S.S.US   U	'   U R                  XB5      nM     U$ )Nr  r   r  withdrawFeeTypefixedr  F)r_  r   transactFeeRateWithdrawT)r   r  r"  )rK  deposit_withdraw_feers  rt  rD  r  rf  $assign_default_deposit_withdraw_fees)r/  r_  rT  r  rw  r  r  r  r  r  withdrawFeewithdrawResults               r1  parse_deposit_withdraw_feehtx.parse_deposit_withdraw_fee!  s   @ h3**3/q#f+&AJ((W=I"..z;LMO11)<KK!N')"..z;PQ&"'"
 #..z;TU&"&"
 +"&/F:{+ >>vPF5 '6 r3  c                    / n[        S[        U5      5       H  nX   nU R                  US5      nUby  U R                  US5      nUU R	                  U5      S.n[        S[        U5      5       H8  n	Xi   n
U R                  X5      nUR                  U R                  X5      5        M:     M  UR                  U R                  X   U5      5        M     U$ )Nr   r  settlement_timer  )rs  rt  rK  r  r  parse_settlementr  rm  )r/  r  r`  rw  rx  
settlementr  r  timestampDetailsr  r  parsedSettlements               r1  r  htx.parse_settlements!  s    J q#k*+A$J??:v6D --j:KL	!* $Y 7*  q#d),A7D'+'<'<T'J$MM$++.>"QR -
 d33KNFKL , r3  c                     U R                  US5      nU R                  US5      nUU R                  XB5      U R                  US5      UU R	                  U5      S.$ )Nr   r  settlement_price)r@  rb  r  r  rT  )r  rD  re  rf  r  )r/  r"  r`  r  rg  s        r1  r!  htx.parse_settlement&"  sd    0 %%j2CD	##J@&&x8%%j2DE"Y/
 	
r3  c                 Z   U R                  5         U R                  U5      nU R                  USS5      nSU0nUb  X'S'   U R                  SXt5      u  ptSnUS   (       aT  US   US'   US	   (       a!  U R	                  U R                  Xt5      5      nOuU R                  U R                  Xt5      5      nOTUS
   (       a)  US   US'   U R                  U R                  Xt5      5      nO![        U R                  S-   US   -   S-   5      eU R                  US/ 5      n	U R                  XX#5      $ )a  
retrieves the public liquidations of a trading pair

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

:param str symbol: unified CCXT market symbol
:param int [since]: the earliest time in ms to fetch liquidations for
:param int [limit]: the maximum number of liquidation structures to retrieve
:param dict [params]: exchange specific parameters for the huobi api endpoint
:param int [params.until]: timestamp in ms of the latest liquidation
:param int [params.tradeType]: default 0, linear swap 0: all liquidated orders, 5: liquidated longs; 6: liquidated shorts, inverse swap and future 0: filled liquidated orders, 5: liquidated close orders, 6: liquidated open orders
:returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
rw  r   Nrx  ry  rO   r=   r   r   rP   rb  z& fetchLiquidations() does not support rX  r[  rY  )rA  r`  r  r  5contractPublicGetLinearSwapApiV3SwapLiquidationOrdersrm  /contractPublicGetSwapApiV3SwapLiquidationOrders/contractPublicGetApiV3ContractLiquidationOrdersr/   r=   r  parse_liquidations)
r/  rb  ri  r  rM  r`  	tradeTypern  rP  rY  s
             r1  fetch_liquidationshtx.fetch_liquidationsH"  s<     	V$%%flA>	)
 $)L!22:wO&>"(,GJhUUVZVaVabiVrsOOPTP[P[\cPlmH &tGHKKDKKX_LhiHtww)QQTZ[aTbbennoo0 ~~h3&&tUBBr3  c                 ~   U R                  US5      nU R                  US5      nU R                  UU R                  X25      U R	                  US5      U R	                  US5      U R	                  US5      U R                  US5      U R	                  US5      U R	                  US5      UU R                  U5      S	.
5      $ )
Nr  rG  r  r  r  r1  r  rN  )
r@  rb  rr  r  r  r2  	baseValue
quoteValuer  rT  )rD  r  safe_liquidationre  rf  r  r  )r/  r  r`  rg  r  s        r1  parse_liquidationhtx.parse_liquidation"  s    " ##KA%%k<@	$$&&x8))+x@ ,,V^D%%k7;**;D))+x@**;8HI"Y/&
  	r3  c                 >   U R                  5         U R                  U5      nU R                  US5      nUS   (       d  [        U R                  S-   5      eU R                  SUS5        US   US.nUb  XVS	'   US
   (       aB  U R                  USS5      nUc  [        U R                  S-   5      eU R                  X5      US'   U R                  U/ SQ5      nSnUS
   (       aL  US   (       a!  U R                  U R                  Xc5      5      nOU R                  U R                  Xc5      5      nO^Sn	U R                  SUS5      u  pU	S:X  a!  U R                  U R                  Xc5      5      nO U R                  U R                  Xc5      5      nU R!                  X5      $ )a  
       closes open positions for a contract market, requires 'amount' in params, unlike other exchanges

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

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

EXCHANGE SPECIFIC PARAMETERS
       :param number [params.amount]: order quantity
       :param str [params.order_price_type]: 'lightning' by default, 'lightning_fok': lightning fok type, 'lightning_ioc': lightning ioc type 'market' by default, 'market': market order type, 'lightning_fok': lightning
       :returns dict: `an order structure <https://docs.ccxt.com/#/?id=position-structure>`
       r   r   z6 closePosition() symbol supports contract markets onlyrZ   r2  r=   )r  r1  Nr!  r   r  r  zP closePosition() requires an extra argument params["amount"] for inverse markets)r   r  r  rO   r{  )rA  r`  rD  r*   r=   check_required_argumentr  r)   r  r  6contractPrivatePostSwapApiV1SwapLightningClosePositionrm  .contractPrivatePostApiV1LightningClosePositionr  AcontractPrivatePostLinearSwapApiV1SwapCrossLightningClosePosition<contractPrivatePostLinearSwapApiV1SwapLightningClosePositionr(  )
r/  rb  r2  rM  r`  r   rn  r  rP  r  s
             r1  close_positionhtx.close_position"  s   ( 	V$((Aj!TWW'__``$$_dFC#D\
 $)6%&)''(CF~'  3E  )E  F  F $ 8 8 HGH6#HI)f~VVW[WbWbcjWstNNt{{[bOklJ!%!C!COU[]d!eJW$aabfbmbmnub~\\]a]h]hip]yz11r3  r  c                    U R                  5         U(       a  SOSnSnUb  U R                  U5      nSnU R                  SUS5      u  pcSU0nSnUb"  US   (       a  [        U R                  S-   5      eUS	:X  aE  Uc  [        U R                  S
-   5      eUS   US'   U R                  U R                  Xs5      5      nU$ SUS'   U R                  U R                  Xs5      5      nU$ )aP  
set hedged to True or False

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

:param bool hedged: set to True to for hedged mode, must be set separately for each market in isolated margin mode, only valid for linear markets
:param str [symbol]: unified market symbol, required for isolated margin mode
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: "cross"(default) or "isolated"
:returns dict: response from the exchange
	dual_sidesingle_sideNr   r{  position_moder   z4 setPositionMode can only be used for linear marketsr|  zD setPositionMode requires a symbol argument for isolated margin moder=   r  r!  )	rA  r`  r  r*   r=   r)   8contractPrivatePostLinearSwapApiV1SwapSwitchPositionModerm  =contractPrivatePostLinearSwapApiV1SwapCrossSwitchPositionMode)	r/  r  rb  rM  posModer`  r  rn  rP  s	            r1  set_position_modehtx.set_position_mode"  s    	!'+][[(F
!??@QSY[bc
W
 VI%6TWW']]^^#~'2x(xyy(.tG$%TTUYU`U`ahUqrH8  )/G$%YYZ^ZeZefmZvwH r3  )r  )N)NN)__name__
__module____qualname____firstlineno__r   r,  rU  r   r]  dictr   r!   rh  r%  rp  r   ry  ru  r   r}  r  r$   r  r  r  r   r  r  r   r&  r.  r5  r   rB  r    rg  rl  rk  r  r  r  r  r  r   r  r  r  r	   r  r  r  r   r  r)  r  r4  r9  r<  rU  rX  r   r\  r_  rt  r  r(  r  r  r   r   r   r  r  r  r  r   r  r  r)  r(  rA  rE  r
   rN  r   rU  r]  re  r"   ro  rr  r  r  r   r#   r  r   r   r  r   r  r  r   r  r  r  r   r  r   r
  r  r<  r=  intrN  rW  r_  rd  r  r   r  r  r  r   r  r  r   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r/  r5  r=  boolrF  __static_attributes____classcell__)r0  s   @r1  r9   r9       s   I# IV* #% [
z !# ;s ;<
T 
6 
EX 
( 57 !5 !5;N !5F 7;2 G  :< PS P@ :>b 
3 
4x $&  $v,  D RT Zs ZS Zx  3   D]4 ] ]6 ]~ 02 N3 Nf N` 04B hHW hH7 hHT 48 c5 c5J
f 
  :>b Trs Tr3 TrY TrlI Iv I IV 9=4^bkm NS N# NS NX[ N, >BPTcgpr G# Gs G# G]` G* -1tRV_a Y?c Y? Y?C Y?v 6:UW HY3 HYs HY# HY\`af\g HYT
 
4 
, 9=4^bkm H# H# HS HX[ Hrvw{r| HB %' )4= ).
& EIX\eg #6S #6c #6RU #6J ') qZ qfAC Ac A AQc Q Q Q $& p( pd	 26b H'c H'3 H'T
 AESWfjsu A=# A=S A=`c A=F /3TXac Y Y3 Yc Y 6:[_hj rs r# rUX r 37TX\eg [?C [?s [?RU [?z :>D_cln ^3 ^c ^Y\ ^ *.Dt\^ !H3 !Hc !H !Hcghmcn !HF 154VZce  S#  SS  SPS  Sjnotju  SD /3TXac ]? ]?3 ]?c ]?hlmrhs ]?~: :*j jv j jX RT N N5 N$ x|  UY  w{  DF LC Ly LPY Lch Lqt L  OR L  qt L  KP L* tx  AC f, f,9 f,I f,_d f,mp f,P x|  EG U,C U,y U,PY U,ch U,qt U,n gksu `03 `0i `0y `0RW `0`c `0D @B r1D$6 r1h 37r ys yC yv ;?r R.c R.C R.h4l /32 s2 s2j <> s 6
h 
4 DF 0s 0$~J^ 0B 79 5# 5^ 5" 8<VX S @ *.Dt\^ 6Q3 6Qc 6Q 6Qcghsct 6Qp -1tRV_a 4Qc 4Q 4QC 4Qfjkvfw 4QlZ
T Z
X Z
Q\ Z
x:s :0 KOWY 6:S 6:% 6:# 6:C 6:^i 6:p
t 
x 
= 
. [] R7S R7% R7c R7c R7an R7h 24 )68K )6V)
t )
V )
Oa )
V 8<$]ajl LY LYC LYWZ LY\+
6 +
[ +
Z? 68 '7 '7K '7R 6:" 277 27 27h 15DW[jnwy ;Q# ;Qc ;QQT ;Qdg ;Q  C  DR  S ;Qz9
$ 9
 9
. 9
vD &eBSW lP\c 3 S # X\ dg B 37TX\eg R>C R>s R>RU R>h 9=R GS G# GR
6 
8Xt XV Xt 26b FPw FPT(^ FPP 24 xS xt3&%t %x %; %N (,$TZ\ I? I?C I?s I?aefqar I?V 7;2 'IG 'I- 'IR $|J\ 0 BFTXgktv pM# pMc pMad pMd 7;2 [8G [8z 79 d# dLBF BH TV !S ! !U !F DF  U @ LN &C &s &P <> $s $L
 
B 6:[_hj `6s `6# `6UX `6D <@ 1I 1If= =~5n 
D <@d[] =C =CS =C =C~V @ =A 32S 32	 32PU 32j =A : :c : :r3  r9   )>ccxt.base.exchanger   ccxt.abstract.htxr   r/  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   typingr$   ccxt.base.errorsr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   ccxt.base.decimal_to_precisionr5   r6   ccxt.base.preciser7   r9    r3  r1  <module>rY     s    ( )  @  @  @  @  @  @  @  @  @  * 0 - . . ' & . ) * ) , . 1 * + 3 4 %vK(K vKr3  