HTX (formerly Huobi) is an international multi-language cryptocurrency exchange. The HTX API component provides an HTTP REST API to complement the existing Huobi WebSocket API.
You can configure the following properties in the Huobi property (for WebSocket) or HTXOptions property (for REST API).
The HTX component extends the Huobi WebSocket API client. When the client successfully connects to HTX servers, the event OnConnect is fired. If the ApiKey is not empty, the client will attempt to connect to the private websocket server, so only the private methods will be available. If the ApiKey is empty, the client will connect to the public websocket server and only the public methods will be available.
TsgcWebSocketClient oClient = new TsgcWebSocketClient();
TsgcWS_API_Huobi oHTX = new TsgcWS_API_Huobi();
oHTX.Client = oClient;
oHTX.Huobi.ApiKey = "your_api_key";
oHTX.Huobi.ApiSecret = "your_api_secret";
oClient.Active = true;
void OnConnect(TsgcWSConnection Connection)
{
DoLog("#HTX Connected");
}
The HTX client implements the following events to control the connection flow and get data sent from the WebSocket server:
The WebSocket API provides real-time market data updates. See the Huobi API documentation for the full list of WebSocket subscription methods including public channels (SubscribeKLine, SubscribeMarketDepth, SubscribeTradeDetail, etc.) and private channels (SubscribeOrderUpdates, SubscribeTradeClearing, SubscribeAccountChange).
The REST API provides Public and Private methods to request data from markets and private accounts. The REST API is accessed through the TsgcHTTP_API_HTX component.
Market Data (Public)
| Method | Description |
| GetServerTime | Get the server time. |
| GetSymbols | Get the list of available trading symbols. |
| GetCurrencys | Get the list of supported currencies. |
| GetMarketTickers | Get tickers for all trading symbols. |
| GetMarketDetail | Get the 24-hour market detail for a symbol. |
| GetMarketDepth | Get the order book depth for a symbol. Supports configurable depth type and depth levels. |
| GetMarketTrade | Get the most recent trade for a symbol. |
| GetMarketHistoryTrade | Get the most recent trades history for a symbol. |
| GetMarketHistoryKline | Get candlestick/kline data. Supports multiple periods (1min, 5min, 15min, 30min, 60min, 4hour, 1day, 1mon, 1week, 1year). |
Trading (Private)
| Method | Description |
| PlaceOrder | Place a new order. Supports buy-market, sell-market, buy-limit, sell-limit and other order types. |
| CancelOrder | Cancel an existing order by order ID. |
| GetOrder | Get details of a specific order. |
| GetOpenOrders | Get the list of open orders for an account. |
| GetOrderHistory | Get the order history for a symbol. |
Account (Private)
| Method | Description |
| GetAccounts | Get the list of accounts. |
| GetAccountBalance | Get the balance of a specific account. |
| GetAccountAssetValuation | Get the total asset valuation for an account type (e.g. spot). |
Find below an example of using the REST API.
TsgcHTTP_API_HTX oHTX = new TsgcHTTP_API_HTX();
oHTX.HTXOptions.ApiKey = "your_api_key";
oHTX.HTXOptions.ApiSecret = "your_api_secret";
// Get market tickers
oHTX.GetMarketTickers();
// Get kline data
oHTX.GetMarketHistoryKline("btcusdt", "1min", 150);
// Place an order
oHTX.PlaceOrder("12345678", "btcusdt", "buy-limit", "0.001", "50000");
// Get account balance
oHTX.GetAccountBalance("12345678");