Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
AscendEx
Backpack
BigONE
Binance
Bitfinex
bitFlyer
Bitget
Bithumb
Bitstamp
Bybit
Coincheck
Coinone
CoinW
Crypto.com
DeepCoin
Deribit
DigiFinex
Gate
Gemini
HashKey
HitBTC
HTX
Korbit
Kraken
KuCoin
LBank
MEXC
OKX
Poloniex
Upbit
WEEX
WOO X
Zaif
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

Huobi (Spot): HTX (Huobi) spot, plus isolated and cross margin accounts; it connects to api.huobi.pro by default. It uses an HTX API Key (Access Key and Secret Key); orders and balance queries use the key's spot account (or the margin account switched to).

Futures_HuobiDM (Futures): HTX (Huobi) USDT-margined perpetual and delivery contracts, and coin-margined perpetual and delivery contracts; it connects to api.hbdm.com by default (the three kinds belong to HTX's separate USDT-margined, coin-margined perpetual and coin-margined delivery APIs). It uses an HTX API Key (Access Key and Secret Key); classic accounts, unified accounts and multi-asset margin mode are supported.

Names and Configuration
exchange.GetName()TypeAliases
HuobiSpot—
Futures_HuobiDMFuturesFutures_HTX, HuobiDM

✓ marks the exchange objects that have the field.

FieldHuobiFutures_HuobiDMRequiredDescription
Access Key✓✓Yes—
Secret Key✓YesThe Secret Key paired with the API Key. For an HTX key that requires an extra ECDSA signature, write it as Secret Key,PEM private key (the part after the comma is a secp256k1 private key in PEM); requests then carry PrivateSignature in addition to the HMAC signature.
Secret Key✓Yes—

Trading Pairs and Contract Codes
Huobi (Spot)

Pair examples: BTC_USDT, ETH_BTC

Pairs are written as BTC_USDT without a contract code; symbols with a contract suffix such as .swap are rejected (use a Futures_HuobiDM exchange object for contracts). HTX trading pairs with Chinese names are supported, for example 币安人生_USDT.

Futures_HuobiDM (Futures)

Pair examples: BTC_USDT, BTC_USD

The quote currency selects the contract family: BTC_USDT is USDT-margined, BTC_USD is coin-margined; other quote currencies are not supported.

Contract codeDescription
swapPerpetual contract (the default).
this_weekCurrent-week delivery contract.
next_weekNext-week delivery contract.
quarterCurrent-quarter delivery contract.
next_quarterNext-quarter delivery contract.

Delivery contracts are looked up by contract type in the HTX instrument list; a tier the exchange has not listed is rejected.

Native contract code examples: BTC-USDT-260925, BTC260925

Delivery contracts can also be given by their HTX native code: BTC_USDT.BTC-USDT-260925 for USDT-margined, BTC_USD.BTC260925 for coin-margined.

Exchange-specific IO Commands
Huobi (Spot)
CommandDescriptionReturns
trade_marginSwitch to the isolated margin account; subsequent orders use the pair's isolated margin account (source=margin-api).The command name itself.
trade_super_marginSwitch to the cross margin account; subsequent orders and balance queries use the cross margin account (source=super-margin-api).The command name itself.
trade_normalSwitch back to the normal spot account (the default).The command name itself.

For the common commands api, base and currency see exchange.IO.

Futures_HuobiDM (Futures)
CommandArgumentsDescriptionReturns
crossboolCross (true, the default) / isolated (false) margin, effective for USDT-margined contracts on classic and unified accounts only. (more below the table)Null also on success; check GetLastError() afterwards when needed.
dualbool[, symbol]Hedge (true, dual_side) / one-way (false, single_side) position mode; sends a switch request to the exchange. USDT-margined contracts only. On classic and unified accounts it switches the cross or isolated account (isolated per the contract's pair) according to the current cross setting.Null also on success; check GetLastError() afterwards when needed.
unifiedboolSends a request switching the account to a unified (true) / classic (false) account; the account shape is detected again after success.Null also on success; check GetLastError() afterwards when needed.
signHoststringSet the address used by private (signed) requests; a bare host name (such as api.hbdm.vn) keeps the scheme of the API base address. HTX includes the host in the signature; once set, both the host in the signature and the address private requests (account, positions, orders, etc.) are actually sent to change to it, while public market data still uses the API base address; without it both use the API base address.Null also on success.

The rest of the longer descriptions in the table:

  • cross: Kept locally with no request to the exchange and applies to all contracts: subsequent USDT-margined orders, cancellations, conditional orders, and position and order queries use the API of that mode (on a classic account exchange.GetAccount() and exchange.GetAssets() sum cross and isolated). Multi-asset margin mode is always cross and is not affected.

For the common commands api, base and currency see exchange.IO.

Common Usage
Send private requests to an alternative domain (market data keeps the API base address) (Futures_HuobiDM only)
javascript
function main() { // Private requests (account, positions, orders, etc.) now go to api.hbdm.vn, // and the signature uses this host exchange.IO("signHost", "https://api.hbdm.vn") Log(exchange.GetAccount()) // Public requests such as market data still go to the API base address Log(exchange.IO("base"), exchange.GetTicker("BTC_USDT.swap")) }

Function Support
All exchange objects

Not supported (the call fails with an error and returns null): exchange.ModifyOrder, exchange.ModifyConditionOrder.

Huobi (Spot)

Served through a fallback:

  • exchange.GetRecords: Native periods are 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w, 1M, 1y; other periods are synthesized by the docker.
Futures_HuobiDM (Futures)

Served through a fallback:

  • exchange.GetRecords: Native periods are 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w, 1M; other periods are synthesized by the docker.

Margin, Account and Simulation
Huobi (Spot)

Account: The wallet mode is kept locally; after switching, orders and balance queries use the corresponding margin account. Isolated margin accounts are per pair, so exchange.GetAccount() and exchange.GetAssets() cannot tell which pair's isolated account to use and fail in isolated mode; likewise, exchange.GetOrders() and exchange.GetConditionOrders() need a pair in isolated mode.

Futures_HuobiDM (Futures)

Margin mode: USDT-margined contracts default to cross margin; switch to isolated with exchange.IO("cross", false) (affects subsequent trading and queries, see that command). Coin-margined contracts are isolated, and multi-asset margin mode is cross. Classic and unified accounts have no separate leverage API: exchange.SetMarginLevel() is kept locally and takes effect with the contract's subsequent orders (lever_rate); without it the contract's current leverage is read from the account, and when the account has none (for example a contract never traded) orders fail until exchange.SetMarginLevel() is called. In multi-asset margin mode exchange.SetMarginLevel() sets the leverage on the exchange directly.

Position mode: Switch hedge/one-way mode for USDT-margined contracts with exchange.IO("dual", bool).

Account: The connector detects the shape of the USDT-margined account (classic, unified, multi-asset margin) and uses the matching API; after switching the account type with exchange.IO("unified", bool) it detects again.

Notes
Huobi (Spot)
  • The amount of a market buy order is the quote-currency amount to spend; a market sell order is in base currency. Conditional buy orders that execute at market after triggering are also placed by quote-currency amount (orderValue).
  • Limit orders support tif ioc, fok and post-only (postOnly, HTX's limit-maker).
  • exchange.GetHistoryOrders() and exchange.GetHistoryConditionOrders() need a pair (the current pair when omitted); an empty string fails.
  • Conditional orders use HTX algo orders (/v2/algo-orders), are available on the normal spot account only, and support take-profit and stop-loss only, not OCO. A conditional order's ID is its clientOrderId (a UUID is generated when none is given), not a numeric order ID.
Futures_HuobiDM (Futures)
  • Order and position amounts are contract counts (integers); what one contract represents is the CtVal in exchange.GetMarkets(): some base currency for USDT-margined contracts, some USD for coin-margined contracts.
  • On classic and unified accounts market orders are placed at the opponent price (opponent); in multi-asset margin mode they are market orders. Limit orders support tif ioc, fok and post-only (postOnly).
  • Conditional orders support take-profit and stop-loss only, not OCO; they are also available in multi-asset margin mode. Without an order price, the triggered order executes at the best 20 levels (optimal_20).
  • Range queries in exchange.GetConditionOrders() support USDT only (such as USDT.swap); coin-margined contracts need a specific contract. On classic and unified accounts exchange.GetHistoryConditionOrders() does not support the since argument (fails when it is given) and only covers the last 90 days.