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
Metadata
Release files for hummingbot-api-client-quang 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hummingbot_api_client_quang-0.1.0.tar.gz | 27.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hummingbot_api_client_quang-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.8 kB
Release files / hummingbot_api_client_quang-0.1.0.tar.gz
| Download URL | hummingbot_api_client_quang-0.1.0.tar.gz |
|---|---|
| Size | 27.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58fb28df71cd61436ae67024020df3fa8f79549ad34ca711f3690e4b5c14435f
|
|
BLAKE2b-256 checksum How to use checksums |
23e05797e6da98dc8365319d30502136fe1248867867a59f4866fb6794e151f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / hummingbot_api_client_quang-0.1.0-py3-none-any.whl
| Download URL | hummingbot_api_client_quang-0.1.0-py3-none-any.whl |
|---|---|
| Size | 30.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5bd7a294e9f51211256a8e504c12450461a74fc0c33be660ee4a0af4d480056
|
|
BLAKE2b-256 checksum How to use checksums |
3acbf8e4c4bc1595dce20195bb962e8058141aa9eb4c5af82fc57a2e862fbf66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|