An async Python client for Hummingbot API
Project description
hummingbot-api-client
An async Python client for the Hummingbot API with modular router support.
Installation
pip install hummingbot-api-client
Quick Start
import asyncio
from hummingbot_api_client import HummingbotAPIClient
async def main():
# Using context manager (recommended)
async with HummingbotAPIClient("http://localhost:8000", "admin", "admin") as client:
# Get portfolio state
portfolio = await client.portfolio.get_state()
print(f"Portfolio value: ${sum(b['value'] for a in portfolio.values() for c in a.values() for b in c):.2f}")
# List available connectors
connectors = await client.connectors.list_connectors()
print(f"Available connectors: {len(connectors)}")
# Check Docker status
docker_status = await client.docker.is_running()
print(f"Docker running: {docker_status['is_docker_running']}")
asyncio.run(main())
Prerequisites
Before using the client, ensure:
- The Hummingbot API is running on
http://localhost:8000(default) - Authentication credentials are configured (default:
admin:admin) - Docker is running (for Docker-related operations)
- Required dependencies are installed
API Client Features
The client provides access to all Hummingbot API functionality through specialized routers:
Core Routers
🐳 Docker Router (client.docker)
Container and image management for Hummingbot Docker instances.
Key features:
- Check Docker daemon status
- List/start/stop/remove containers
- Pull Docker images with progress monitoring
- Clean up exited containers
- Filter containers by name
Common methods:
is_running()- Check if Docker is runningget_active_containers()- List all running containersstart_container(name)- Start a stopped containerstop_container(name)- Stop a running containerpull_image(name, tag)- Pull a Docker image
👤 Accounts Router (client.accounts)
Manage trading accounts and exchange credentials.
Key features:
- Create and delete trading accounts
- Add/update/delete exchange credentials
- List configured connectors per account
- Secure credential storage
Common methods:
list_accounts()- Get all account namesadd_account(name)- Create new accountadd_credential(account, connector, credentials)- Add exchange credentialslist_account_credentials(account)- List connectors with credentials
💰 Trading Router (client.trading)
Execute trades and manage orders across exchanges.
Key features:
- Place market and limit orders
- Cancel active orders
- Monitor open positions
- Track trade history with pagination
- Access funding payments (perpetuals)
- Configure leverage and position modes
Common methods:
place_order(account, connector, pair, type, amount, ...)- Place an ordercancel_order(account, connector, order_id)- Cancel an orderget_active_orders()- List all active ordersget_positions()- Get current positionsget_trades()- Get trade historyset_leverage(account, connector, pair, leverage)- Set leverage
💼 Portfolio Router (client.portfolio)
Monitor and analyze portfolio performance.
Key features:
- Real-time portfolio state across all accounts
- Token distribution analysis
- Account balance tracking
- Historical portfolio data
- Value calculations in USD
Common methods:
get_state()- Get current portfolio stateget_total_value()- Calculate total portfolio valueget_distribution()- Get token distribution percentagesget_token_holdings(token)- Find specific token holdingsget_portfolio_summary()- Get comprehensive summary
🔌 Connectors Router (client.connectors)
Access exchange connector information.
Key features:
- List available exchange connectors
- Get configuration requirements
- Access trading rules (min/max amounts, tick sizes)
- Supported order types per exchange
Common methods:
list_connectors()- List all available connectorsget_config_map(connector)- Get required configuration fieldsget_trading_rules(connector, pairs)- Get trading rulesget_supported_order_types(connector)- Get supported order types
Bot Management Routers
🤖 Bot Orchestration Router (client.bot_orchestration)
Manage bot lifecycle and deployment.
Key features:
- Start/stop/restart bots
- Deploy V2 scripts and controllers
- Monitor bot status via MQTT
- Get bot performance metrics
- Archive bot data
- Track bot runs with filtering
Common methods:
start_bot(name, script, config)- Start a botstop_bot(name)- Stop a botget_bot_status(name)- Get bot statusdeploy_v2_script(name, profile, script, config)- Deploy a script botdeploy_v2_controllers(name, profile, controllers)- Deploy controller botget_bot_runs()- Get bot run history
📋 Controllers Router (client.controllers)
Manage V2 strategy controllers.
Key features:
- List available controller types
- Create/update/delete controllers
- Manage controller configurations
- Get controller templates
- Bot-specific controller configs
Common methods:
list_controllers()- List all controllers by typeget_controller(type, name)- Get controller contentcreate_or_update_controller(type, name, data)- Create/update controllerlist_controller_configs()- List all configurationsget_bot_controller_configs(bot)- Get bot's controller configs
📜 Scripts Router (client.scripts)
Manage traditional Hummingbot scripts.
Key features:
- List available scripts
- Create/update/delete scripts
- Manage script configurations
- Get configuration templates
Common methods:
list_scripts()- List all scriptsget_script(name)- Get script contentcreate_or_update_script(name, data)- Create/update scriptlist_script_configs()- List all script configurationsget_script_config_template(name)- Get config template
📊 Backtesting Router (client.backtesting)
Run strategy backtests.
Key features:
- Run backtesting simulations
- Configure time periods and resolution
- Set trading costs
- Custom configuration options
Common methods:
run_backtesting(start_time, end_time, resolution, trade_cost, config)- Run backtest
🗄️ Archived Bots Router (client.archived_bots)
Analyze historical bot data.
Key features:
- List database files
- Get performance analysis
- Access trade/order history
- View executor and position data
- Analyze controller configurations
Common methods:
list_databases()- List all database filesget_database_performance(db)- Get performance metricsget_database_trades(db, limit, offset)- Get trade historyget_database_orders(db, limit, offset, status)- Get order historyget_database_positions(db)- Get position data
📈 Market Data Router (client.market_data)
Access real-time and historical market data.
Key features:
- Real-time price feeds
- Historical candle data (OHLCV)
- Order book snapshots
- Funding rates (perpetuals)
- Volume/price analysis
- VWAP calculations
Common methods:
get_candles(connector, pair, interval, max_records)- Get real-time candlesget_historical_candles(connector, pair, interval, start, end)- Get historical dataget_prices(connector, pairs)- Get current pricesget_order_book(connector, pair, depth)- Get order bookget_funding_info(connector, pair)- Get funding ratesget_vwap_for_volume(connector, pair, volume, is_buy)- Calculate VWAP
Examples
Jupyter Notebooks
The library includes comprehensive Jupyter notebooks demonstrating usage for each router. These provide interactive, step-by-step tutorials with explanations:
Note: Jupyter notebooks are not included in the repository by default. To run the example notebooks, install Jupyter:
pip install jupyter notebook
# or
pip install jupyterlab
Example notebooks cover:
- Basic usage demonstrating all features
- Router-specific examples (docker, accounts, trading, portfolio, connectors)
- Advanced patterns and error handling
- Real-time monitoring and bot management
Each notebook provides interactive demonstrations of the complete functionality with real API calls and detailed explanations.
Advanced Usage
Error Handling
async with HummingbotClient("http://localhost:8000", "admin", "admin") as client:
try:
orders = await client.trading.search_orders({"limit": 10})
print(f"Found {len(orders['data'])} orders")
except aiohttp.ClientResponseError as e:
print(f"API error: {e.status} - {e.message}")
except Exception as e:
print(f"Unexpected error: {e}")
Pagination
async def get_all_orders(client):
"""Fetch all orders using pagination."""
all_orders = []
cursor = None
while True:
filter_request = {"limit": 100}
if cursor:
filter_request["cursor"] = cursor
response = await client.trading.search_orders(filter_request)
all_orders.extend(response["data"])
pagination = response["pagination"]
if not pagination["has_more"]:
break
cursor = pagination["next_cursor"]
return all_orders
Custom Timeout
import aiohttp
# Create client with custom timeout
timeout = aiohttp.ClientTimeout(total=60) # 60 seconds
client = HummingbotClient(
"http://localhost:8000",
"admin",
"admin",
timeout=timeout
)
Building
# Install build dependencies
uv pip install build
# Build the package
python -m build
# Install in development mode
pip install -e .
License
Apache License 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hummingbot_api_client-1.4.0.tar.gz.
File metadata
- Download URL: hummingbot_api_client-1.4.0.tar.gz
- Upload date:
- Size: 38.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d78f8eded862c710e53f2c3e8ad489bdca4059df046835b9048d556695bb78ef
|
|
| MD5 |
10166c1b2db856027168502a50450622
|
|
| BLAKE2b-256 |
dd8bfd19169efca6e130ddba499aacb7680962dea73a9a9a2999e8def5b6dd55
|
Provenance
The following attestation bundles were made for hummingbot_api_client-1.4.0.tar.gz:
Publisher:
publish-to-pypi.yml on hummingbot/hummingbot-api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hummingbot_api_client-1.4.0.tar.gz -
Subject digest:
d78f8eded862c710e53f2c3e8ad489bdca4059df046835b9048d556695bb78ef - Sigstore transparency entry: 1191918010
- Sigstore integration time:
-
Permalink:
hummingbot/hummingbot-api-client@e3109a1743c3cb5cd3bbdb3bf1f1560509ece1dd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hummingbot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@e3109a1743c3cb5cd3bbdb3bf1f1560509ece1dd -
Trigger Event:
push
-
Statement type:
File details
Details for the file hummingbot_api_client-1.4.0-py3-none-any.whl.
File metadata
- Download URL: hummingbot_api_client-1.4.0-py3-none-any.whl
- Upload date:
- Size: 44.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec57e1ef72ec95255772f0d1c6975a83bc55f721fe06da48eb1b7d5e220a8e8d
|
|
| MD5 |
f9ba0a3b05c3da2042ea2c43d220f5fb
|
|
| BLAKE2b-256 |
71d5439c720bf841fb8c0cf80f53a012edf3313de6c85923f94b146c40586683
|
Provenance
The following attestation bundles were made for hummingbot_api_client-1.4.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on hummingbot/hummingbot-api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hummingbot_api_client-1.4.0-py3-none-any.whl -
Subject digest:
ec57e1ef72ec95255772f0d1c6975a83bc55f721fe06da48eb1b7d5e220a8e8d - Sigstore transparency entry: 1191918018
- Sigstore integration time:
-
Permalink:
hummingbot/hummingbot-api-client@e3109a1743c3cb5cd3bbdb3bf1f1560509ece1dd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hummingbot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@e3109a1743c3cb5cd3bbdb3bf1f1560509ece1dd -
Trigger Event:
push
-
Statement type: