SDKs overview
Huobi provides a set of official Software Development Kits (SDKs) and maintains comprehensive API documentation to assist developers in building applications that interact with the exchange. These SDKs are designed to abstract the complexities of direct API calls, offering language-specific methods for common operations such as retrieving market data, placing orders, and managing user accounts. The official SDKs support several popular programming languages, including Python, Java, C#, Go, and JavaScript, facilitating integration for a broad range of development environments.
Interactions with the Huobi platform via SDKs typically involve two primary API types: RESTful APIs for request/response interactions and WebSocket APIs for real-time data streams. Developers can use the RESTful API for operations like fetching historical data or executing trades, while the WebSocket API is crucial for applications requiring immediate updates on market prices, order book changes, or account balances. The provision of these SDKs aims to streamline the development process, allowing developers to focus on application logic rather than low-level API communication protocols.
Official SDKs by language
Huobi has developed and maintained official SDKs for several programming languages. These SDKs are typically hosted on platforms like GitHub and distributed through standard package managers for each language. The official SDKs aim to provide stable and feature-rich interfaces for interacting with Huobi's various trading functionalities, including spot, futures, and margin trading, as well as accessing market data.
| Language | Package/Repository | Install Command | Maturity |
|---|---|---|---|
| Python | huobi-client (often via PyPI) |
pip install huobi-client |
Stable, actively maintained |
| Java | huobi-java-sdk (often via Maven/Gradle) |
Maven: Add dependency to pom.xml; Gradle: Add dependency to build.gradle |
Stable, actively maintained |
| C# | Huobi.SDK.Csharp (via NuGet) |
dotnet add package Huobi.SDK.Csharp |
Stable, actively maintained |
| Go | go-sdk (via Go modules) |
go get github.com/huobiapi/go-sdk |
Stable, actively maintained |
| JavaScript | huobi-api-js (via npm) |
npm install huobi-api |
Stable, actively maintained |
Installation
Installing Huobi SDKs follows the typical process for each respective programming language's package ecosystem. Below are general instructions for the officially supported SDKs.
Python
The Python SDK is commonly distributed via PyPI, the Python Package Index. Users can install it using pip, Python's package installer.
pip install huobi-client
It's advisable to use a virtual environment to manage dependencies for specific projects, which helps prevent conflicts with other Python projects on the system.
Java
The Java SDK is typically managed using build automation tools like Maven or Gradle. Developers need to add the appropriate dependency entry to their project's configuration file.
Maven (pom.xml)
<dependency>
<groupId>com.huobi.client</groupId>
<artifactId>huobi-java-sdk</artifactId>
<version>[latest_version]</version>
</dependency>
Gradle (build.gradle)
implementation 'com.huobi.client:huobi-java-sdk:[latest_version]'
Replace [latest_version] with the current stable version number available from the Huobi SDK repository or Maven Central.
C#
The C# SDK is distributed as a NuGet package, which is the package manager for .NET. It can be installed using the .NET CLI or the NuGet Package Manager in Visual Studio.
.NET CLI
dotnet add package Huobi.SDK.Csharp
NuGet Package Manager Console
Install-Package Huobi.SDK.Csharp
Go
The Go SDK is integrated using Go modules, which is the standard dependency management system for Go projects. The go get command fetches the module and its dependencies.
go get github.com/huobiapi/go-sdk
After fetching, Go modules typically handle the versioning and integration into the project's go.mod file.
JavaScript
The JavaScript SDK is available via npm, the package manager for Node.js. It can be installed in a project using the npm install command.
npm install huobi-api
This command will add the SDK to the project's node_modules directory and update the package.json file.
Quickstart example
This Python example demonstrates how to retrieve the latest market tickers for Huobi using the official Python SDK. Before running, ensure you have installed the huobi-client package as described in the installation section.
from huobi.client.market import MarketClient
def get_latest_tickers():
# Initialize the MarketClient. No API key/secret needed for public market data.
market_client = MarketClient()
try:
# Get latest market tickers for all trading pairs
# The response is a list of Ticker objects
tickers = market_client.get_latest_tickers()
if tickers:
print("Latest Huobi Market Tickers:")
for ticker in tickers:
print(f" Symbol: {ticker.symbol}, Close: {ticker.close}, High: {ticker.high}, Low: {ticker.low}, Volume: {ticker.vol}")
else:
print("No tickers found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
get_latest_tickers()
This script initializes a MarketClient object, which is used to access public market data. It then calls get_latest_tickers() to fetch a list of all available trading pair tickers. For each ticker, it prints the symbol, current closing price, 24-hour high, 24-hour low, and 24-hour trading volume. This example highlights the SDK's ability to abstract API calls into simple, readable method invocations, a common feature across many modern SDKs.
Community libraries
In addition to the official SDKs, the broader developer community often contributes third-party libraries and wrappers for interacting with APIs. While these community-driven projects can offer alternative functionalities, support for additional languages, or specific optimizations, developers should exercise caution. It is crucial to verify the security, reliability, and maintenance status of any third-party library before integrating it into production systems. Reviewing the source code, checking for active development, and reading user reviews are recommended steps.
For Huobi, community libraries might emerge to cater to niche use cases, experimental features, or languages not officially supported. These can often be found on platforms like GitHub or package repositories specific to their respective languages. Developers interested in contributing or exploring community efforts for Huobi's API should search these platforms, often using keywords like "Huobi API" or "Huobi client" combined with the programming language of interest.