Huobi.Net

Huobi.Net is a strongly typed client library for accessing the Huobi REST and Websocket API. All data is mapped to readable models and enum values. Additional features include an implementation for maintaining a client side order book, easy integration with other exchange client libraries and more.

This library is based on the CryptoExchange.Net base package and can be used in combination with other exchange packages!

Supported Frameworks

The library is targeting both .NET Standard 2.0 and .NET Standard 2.1 for optimal compatibility

.NET implementation Version Support
.NET Core2.0 and higher
.NET Framework4.6.1 and higher
Mono5.4 and higher
Xamarin.iOS10.14 and higher
Xamarin.Android8.0 and higher
UWP10.0.16299 and higher
Unity2018.1 and higher

Discord

A Discord server is available here. Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.

Support the project

Donate

Make a one time donation in a crypto currency of your choice. If you prefer to donate a currency not listed here please contact me.

Btc: bc1q277a5n54s2l2mzlu778ef7lpkwhjhyvghuv8qf
Eth: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7
USDT (TRX): TKigKeJPXZYyMVDgMyXxMf17MWYia92Rjd

Sponsor

Alternatively, sponsor me on Github using Github Sponsors.

I develop and maintain these packages on my own for free in my spare time, any support is greatly appreciated.

Getting Started

The packge is available on Nuget. After installing the package the Huobi API is available by using the HuobiRestClient and HuobiSocketClient.

More information and usage documentation is available at the CryptoExchange.Net documentation page

Installation

Add the package via dotnet, or add it via the package manager.

dotnet add package Huobi.Net

API Access

Huobi.Net can be configured using Dotnet dependency injection, after which the clients can be injected into your services. It also correctly configures logging and HttpClient usage.

builder.Services.AddHuobi(options => {
  // Options can be configured here, for example:
  options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});

The IHuobiRestClient and IHuobiSocketClient can then be injected.

Alternatively the rest and socket client can be constructed directly

var restClient = new HuobiRestClient(options => {
  // Options can be configured here, for example:
  options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});
var socketClient = new HuobiSocketClient();

Examples

Spot API

Get Symbols

Get a list of supported spot symbols

var huobiClient = new HuobiRestClient();

var result = await huobiClient.SpotApi.ExchangeData.GetSymbolsAsync();
Get Symbol Ticker

Get the 24h price ticker of a spot symbol

var huobiClient = new HuobiRestClient();

var result = await huobiClient.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT");
Get Recent Trades

Get the most recent trades for a spot symbol

var huobiClient = new HuobiRestClient();

var result = await huobiClient.SpotApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT");
Get Balances

Get asset balances of the spot account

var huobiClient = new HuobiRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});

// First need to get the id of the account to get balances for
var accounts = await huobiClient.SpotApi.Account.GetAccountsAsync();
var spotAccountId = accounts.Data.Single(d => d.Type == Huobi.Net.Enums.AccountType.Spot).Id;

var result = await huobiClient.SpotApi.Account.GetBalancesAsync(spotAccountId);
Place Limit Order

Place a new limit order for buying 0.1 ETH at a price of 2000 USDT

var huobiClient = new HuobiRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});

var accounts = await huobiClient.SpotApi.Account.GetAccountsAsync();
var spotAccountId = accounts.Data.Single(d => d.Type == Huobi.Net.Enums.AccountType.Spot).Id;

var result = await huobiClient.SpotApi.Trading.PlaceOrderAsync(
    spotAccountId,
    "ETHUSDT",
    Huobi.Net.Enums.OrderSide.Buy,
    Huobi.Net.Enums.OrderType.Limit,
    0.1m,
    2000);
Place Market Order

Place a new market order for buying 50 USDT worth of ETH at the best available price

var huobiClient = new HuobiRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});

var accounts = await huobiClient.SpotApi.Account.GetAccountsAsync();
var spotAccountId = accounts.Data.Single(d => d.Type == Huobi.Net.Enums.AccountType.Spot).Id;

var result = await huobiClient.SpotApi.Trading.PlaceOrderAsync(
    spotAccountId,
    "ETHUSDT",
    Huobi.Net.Enums.OrderSide.Buy,
    Huobi.Net.Enums.OrderType.Market,
    50);
Get Order Info

Retrieve order information for a specific order

var huobiClient = new HuobiRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});

var result = await huobiClient.SpotApi.Trading.GetOrderAsync(123);
Cancel an order

Cancel a currently active order

var huobiClient = new HuobiRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});

var result = await huobiClient.SpotApi.Trading.CancelOrderAsync(123);

Usdt Margin Swap API

Get Contracts

Get a list of supported margin swap contracts

var huobiClient = new HuobiRestClient();

var result = await huobiClient.UsdtMarginSwapApi.ExchangeData.GetContractInfoAsync();
Get Symbol Ticker

Get the 24h price ticker of a margin swap symbol

var huobiClient = new HuobiRestClient();

var result = await huobiClient.UsdtMarginSwapApi.ExchangeData.GetMarketDataAsync("ETH-USDT");
Get Recent Trades

Get the most recent trades for a margin swap symbol

var huobiClient = new HuobiRestClient();

var result = await huobiClient.UsdtMarginSwapApi.ExchangeData.GetRecentTradesAsync("ETH-USDT", 100);
Get Balances

Get balance of the perpetual futures account

var huobiClient = new HuobiRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});

// First need to get the id of the account to get balances for
var accounts = await huobiClient.SpotApi.Account.GetAccountsAsync();
var accountId = accounts.Data.Single(d => d.Type == Huobi.Net.Enums.AccountType.Margin).Id;

var result = await huobiClient.SpotApi.Account.GetBalancesAsync(accountId);
Get Positions

Get open positions

var huobiClient = new HuobiRestClient(options => {
  options.ApiCredentials = new ApiCredentials("KEY", "SECRET");		  
});

var result = await huobiClient.UsdtMarginSwapApi.Account.GetCrossMarginPositionsAsync();
Place Limit Order

Place a new limit order for going long on 0.1 ETH at a price of 2000 USDT

var huobiClient = new HuobiRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});

var result = await huobiClient.UsdtMarginSwapApi.Trading.PlaceCrossMarginOrderAsync(0.1m, Huobi.Net.Enums.OrderSide.Buy, 10, "ETH-USDT", price: 2000m);