### Re-run Hummingbot API Setup and Deploy Source: https://github.com/hummingbot/hummingbot-api/blob/main/README.md Use these commands if the initial setup script finishes but services do not start. Navigate to the hummingbot-api directory first. ```bash cd hummingbot-api make setup make deploy ``` -------------------------------- ### Example .env for Security Settings Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md Provides an example of how to set security-related environment variables in the .env file. These include username, password, and a master configuration password for encryption. ```bash USERNAME=my-secure-username PASSWORD=my-very-secure-password CONFIG_PASSWORD=my-encryption-password-min-12-chars ``` -------------------------------- ### Install Hummingbot API with Docker Source: https://github.com/hummingbot/hummingbot-api/blob/main/README.md Installs the Hummingbot API using a helper script. Ensure Docker is installed and running before execution. The script will prompt for API credentials and Tailscale configuration. ```bash curl -fsSL https://raw.githubusercontent.com/hummingbot/deploy/main/setup.sh | bash -s -- --hummingbot-api ``` -------------------------------- ### Full .env Example for Hummingbot API Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md A comprehensive example of a .env file with all recommended settings for security, database, MQTT, market data, gateway, AWS S3, CORS, application, and Tailscale. ```bash # ===== Security (REQUIRED FOR PRODUCTION) ===== USERNAME=my-unique-username PASSWORD=my-very-secure-password-32-chars-min CONFIG_PASSWORD=encryption-password-32-chars-min # ===== Database ===== DATABASE_URL=postgresql+asyncpg://hbot:dbpassword@localhost:5432/hummingbot_api # ===== MQTT Broker ===== BROKER_HOST=localhost BROKER_PORT=1883 BROKER_USERNAME=admin BROKER_PASSWORD=broker-password # ===== Market Data ===== MARKET_DATA_CLEANUP_INTERVAL=300 MARKET_DATA_FEED_TIMEOUT=600 MARKET_DATA_CANDLES_READY_TIMEOUT=30 # ===== Gateway (DEX) ===== GATEWAY_URL=https://localhost:15888 # ===== AWS S3 Archiving (optional) ===== AWS_API_KEY= AWS_SECRET_KEY= AWS_S3_DEFAULT_BUCKET_NAME= # ===== CORS (restrict origins in production) ===== CORS_ALLOW_ORIGINS='["https://dashboard.example.com"]' CORS_ALLOW_ORIGIN_REGEX=https://(app|dashboard)\.example\.com CORS_ALLOW_CREDENTIALS=true # ===== Application ===== LOGFIRE_ENVIRONMENT=prod APP_ACCOUNT_UPDATE_INTERVAL=5 # ===== Tailscale (recommended for production) ===== TAILSCALE_ENABLED=true TAILSCALE_AUTH_KEY=tskey-auth-your-auth-key-here TAILSCALE_HOSTNAME=hummingbot-api ``` -------------------------------- ### StartBotAction - Start Bot Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/models-reference.md Defines the action to start a bot. Requires bot name, controller, connector names, trading pairs, and configuration. ```python class StartBotAction(BaseModel): bot_name: str controller: str connector_names: List[str] trading_pairs: List[str] config: Dict[str, Any] ``` -------------------------------- ### start Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Starts the background tasks for monitoring and cleanup of executors. ```APIDOC ## start ### Description Start background executor monitoring and cleanup task. ### Method ```python def start() ``` ``` -------------------------------- ### Start a Trading Bot Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Starts a new trading bot with specified configuration. ```APIDOC ## POST /bot-orchestration/start-bot ### Description Starts a new trading bot with specified configuration. ### Method POST ### Endpoint /bot-orchestration/start-bot ### Parameters #### Request Body - **bot_name** (string) - Required - The name of the bot. - **controller** (string) - Required - The controller for the bot (e.g., pmm). - **connector_names** (array of strings) - Required - A list of exchange connector names to use. - **trading_pairs** (array of strings) - Required - A list of trading pairs for the bot. - **config** (object) - Required - Configuration parameters for the bot (e.g., {"order_amount": "0.01", "bid_spread": "0.001"}). ``` -------------------------------- ### BotsOrchestrator start Method Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Establishes a connection to the MQTT broker and begins listening for bot status updates. ```python def start() ``` -------------------------------- ### List Installed Connectors Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md This command lists all connectors installed in the Hummingbot library. Use it to verify if a specific connector is recognized by the API. ```bash curl -u admin:admin http://localhost:8000/connectors ``` -------------------------------- ### Start a Bot Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Initiates the startup process for a new trading bot. ```APIDOC ## POST /bot-orchestration/start-bot ### Description Start a bot. ### Method POST ### Endpoint /bot-orchestration/start-bot ### Parameters #### Request Body - **bot_name** (string) - Required - The name for the new bot. - **controller** (string) - Required - The controller to use (e.g., "pmm", "dman_v3"). - **connector_names** (List[string]) - Required - A list of exchange connector names to use. - **trading_pairs** (List[string]) - Required - A list of trading pairs for the bot. - **config** (object) - Optional - A dictionary containing controller-specific parameters. ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the bot has started. ``` -------------------------------- ### Install and Run Hummingbot API Source: https://github.com/hummingbot/hummingbot-api/blob/main/README.md Commands to set up the development environment and run the Hummingbot API with hot-reloading. ```bash make install # Create conda environment conda activate hummingbot-api make run # Run with hot-reload ``` -------------------------------- ### Start a Trading Bot Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Initiates the start of a trading bot. Requires bot name, controller type, connector names, trading pairs, and specific configuration parameters. ```bash curl -u admin:admin -X POST http://localhost:8000/bot-orchestration/start-bot \ -H "Content-Type: application/json" \ -d '{ "bot_name": "my-pmm-bot", "controller": "pmm", "connector_names": ["binance"], "trading_pairs": ["BTC-USDT"], "config": {"order_amount": "0.01", "bid_spread": "0.001"} }' ``` -------------------------------- ### Example .env for Database Settings Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md Illustrates the format for setting the DATABASE_URL environment variable in the .env file for PostgreSQL connection. ```bash DATABASE_URL=postgresql+asyncpg://hbot:password@db.example.com:5432/hummingbot_api ``` -------------------------------- ### GatewayService start Method Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Initiates the Gateway service using Docker. Returns a status dictionary including the Gateway URL. ```python async def start() -> Dict[str, Any] ``` -------------------------------- ### Start Gateway Service Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Starts the Gateway service for decentralized exchange trading. The Gateway runs at https://localhost:15888 with mTLS authentication. ```APIDOC ## POST /gateway/start ### Description Start the Gateway service for decentralized exchange trading. ### Method POST ### Endpoint /gateway/start ### Parameters #### Request Body - **(Empty object)** - Required - Empty object `{}` ### Response #### Success Response (200 OK) - Gateway status and URL ### Status Codes - 200 OK - 500 Error ``` -------------------------------- ### Start a Trading Bot Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Initiates the startup of a trading bot, allowing configuration of its controller and operational parameters. ```APIDOC ## POST /bot-orchestration/start-bot ### Description Start a trading bot with specified controller and parameters. ### Method POST ### Endpoint /bot-orchestration/start-bot ### Parameters #### Request Body - **StartBotRequest** (object) - Required - Contains `bot_name`, `controller`, and `config` for the bot. ### Request Example ```json { "bot_name": "my_trading_bot", "controller": "some_controller", "config": { "param1": "value1", "param2": "value2" } } ``` ### Response #### Success Response (200 OK) - `{"message": "Bot started successfully"}` #### Error Response (400 Bad Request) - Invalid request payload or parameters. #### Error Response (500 Error) - Internal server error during bot startup. ``` -------------------------------- ### StartBotAction Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/models-reference.md Represents an action to start a trading bot. Requires bot name, controller, connector names, trading pairs, and configuration. ```APIDOC ## StartBotAction — Start Bot ### Description Initiates the start of a trading bot with specified parameters. ### Request Body - **bot_name** (str) - Required - The name of the bot to start. - **controller** (str) - Required - The controller for the bot. - **connector_names** (List[str]) - Required - A list of connector names to use. - **trading_pairs** (List[str]) - Required - A list of trading pairs for the bot. - **config** (Dict[str, Any]) - Required - Configuration parameters for the bot. ``` -------------------------------- ### Get Portfolio Balances Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Retrieves the current state of the portfolio balances. ```APIDOC ## POST /portfolio/state ### Description Retrieves the current state of the portfolio balances. ### Method POST ### Endpoint /portfolio/state ### Parameters #### Request Body - **refresh** (boolean) - Optional - Whether to refresh the portfolio state before retrieving. ``` -------------------------------- ### Basic Authentication Example Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Use HTTP Basic Auth with your username and password to access API endpoints. Credentials can be set via environment variables. ```bash curl -u USERNAME:PASSWORD http://localhost:8000/accounts ``` -------------------------------- ### Start a Bot Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Initiates the startup of a trading bot. Requires specifying the bot's name, controller type, associated connectors, trading pairs, and controller-specific configuration parameters. ```json { "message": "Bot started successfully" } ``` -------------------------------- ### Credential Encryption Setup Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Set the CONFIG_PASSWORD environment variable to encrypt connector API keys. Stored encrypted in credentials files. ```bash CONFIG_PASSWORD=my-secret-key-min-12-chars ``` -------------------------------- ### Start MarketDataService Cleanup Task Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Initiates the background task responsible for removing stale data feeds. This should be called after initialization. ```python def start() ``` -------------------------------- ### Get All Trading Connectors Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Returns a nested dictionary containing all configured trading connectors, organized by account name and then by connector name. ```python def get_all_trading_connectors() -> Dict[str, Dict[str, ConnectorBase]] ``` -------------------------------- ### Get Portfolio Balances Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Fetches the current state of your portfolio balances. The 'refresh' parameter controls whether to force an update. ```bash curl -u admin:admin -X POST http://localhost:8000/portfolio/state \ -H "Content-Type: application/json" \ -d '{"refresh": false}' ``` -------------------------------- ### Get Funding Rates Request Model Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/models-reference.md Use this model to request funding rates for a specific trading pair from a connector. ```python class FundingInfoRequest(BaseModel): connector_name: str trading_pair: str ``` -------------------------------- ### Get Prices Request Model Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/models-reference.md Use this model to request prices for one or more trading pairs from a specific connector. ```python class PriceRequest(BaseModel): connector_name: str trading_pairs: List[str] ``` -------------------------------- ### Get Current Prices Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieve the current mid, bid, and ask prices for a list of trading pairs from a specific connector. ```json { "connector_name": "binance", "prices": { "BTC-USDT": {"mid": "45000", "bid": "44999.50", "ask": "45000.50"} } } ``` -------------------------------- ### Get Positions with TradingService Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Fetch perpetual positions from all configured perpetual connectors. Returns a list of dictionaries containing position details. ```python async def get_positions( account_names: Optional[List[str]] = None, connector_names: Optional[List[str]] = None ) -> List[Dict[str, Any]] ``` -------------------------------- ### Example Paginated Response Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/types.md Illustrates the JSON structure of a typical paginated response from the API, showing the 'data' array and the 'pagination' object with metadata. ```json { "data": [ {"order_id": "12345", "status": "filled", ...} ], "pagination": { "limit": 100, "has_more": true, "next_cursor": "2024-01-10T12:00:00", "total_count": 500 } } ``` -------------------------------- ### Environment Variable Configuration Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Load Hummingbot API configuration using environment variables. This example shows security, database, MQTT, gateway, market data, CORS, and Tailscale settings. ```bash # Security USERNAME=secure-username PASSWORD=secure-password CONFIG_PASSWORD=encryption-key # Database DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/db # MQTT BROKER_HOST=localhost BROKER_PORT=1883 # Gateway GATEWAY_URL=https://localhost:15888 # Market data MARKET_DATA_CLEANUP_INTERVAL=300 MARKET_DATA_FEED_TIMEOUT=600 # CORS CORS_ALLOW_ORIGINS='["https://dashboard.example.com"]' # Tailscale (optional) TAILSCALE_ENABLED=true TAILSCALE_AUTH_KEY=tskey-auth-... TAILSCALE_HOSTNAME=hummingbot-api ``` -------------------------------- ### Setup Hummingbot API with Tailscale Source: https://github.com/hummingbot/hummingbot-api/blob/main/README.md Enables secure private networking by integrating with Tailscale. This requires a Tailscale auth key and enables the API to be accessed privately within your tailnet. ```bash make setup ``` -------------------------------- ### Hummingbot API Management Commands Source: https://github.com/hummingbot/hummingbot-api/blob/main/README.md A collection of make commands for managing the Hummingbot API services. These include setup, deployment, stopping services, running in development mode, building Docker images, and checking Tailscale status. ```bash make setup ``` ```bash make deploy ``` ```bash make stop ``` ```bash make run ``` ```bash make install ``` ```bash make build ``` ```bash make tailscale-status ``` -------------------------------- ### Initialize Settings Singleton Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md The `Settings()` singleton is loaded once at startup. Configuration changes require a restart to take effect. ```python settings = Settings() ``` -------------------------------- ### Get Funding Information Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Fetches funding rate, next funding time, and rate history for perpetual contracts on a specific trading pair. ```python async def get_funding_info( connector_name: str, trading_pair: str ) -> Dict[str, Any] ``` -------------------------------- ### Get Funding Payments Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Query perpetual funding payments with filters for account, connector, trading pair, time range, and pagination. ```python async def get_funding_payments( account_names: Optional[List[str]] = None, connector_names: Optional[List[str]] = None, trading_pair: Optional[str] = None, start_time: Optional[int] = None, end_time: Optional[int] = None, limit: int = 100, cursor: Optional[str] = None ) -> PaginatedResponse ``` -------------------------------- ### BotsOrchestrator start_bot Method Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Deploys and initiates a bot, specifying its name, the controller to use, and its configuration. ```python async def start_bot( bot_name: str, controller: str, config: Dict[str, Any] ) -> None ``` -------------------------------- ### SwapQuoteRequest - Get Swap Quote Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/models-reference.md Defines the request model for getting a swap quote. Requires connector name, chain, input and output tokens, and the amount to swap. ```python class SwapQuoteRequest(BaseModel): connector_name: str chain: str token_in: str token_out: str amount_in: Decimal ``` -------------------------------- ### PricesResponse - Current Prices Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/models-reference.md Provides the current mid, bid, and ask prices for trading pairs on a connector. Use this to get real-time market price information. ```python class PricesResponse(BaseModel): connector_name: str prices: Dict[str, PriceData] ``` -------------------------------- ### Get Trade Fills Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Query trade fills with filters for account, connector, trading pair, trade type, time range, and pagination. ```python async def get_trades( account_names: Optional[List[str]] = None, connector_names: Optional[List[str]] = None, trading_pairs: Optional[List[str]] = None, trade_types: Optional[List[str]] = None, start_time: Optional[int] = None, end_time: Optional[int] = None, limit: int = 100, cursor: Optional[str] = None ) -> PaginatedResponse ``` -------------------------------- ### Add Account Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Creates a new account directory with default configuration files. Requires the account name as input. ```python def add_account(account_name: str) ``` -------------------------------- ### Add Account Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Creates a new account with default configuration files. ```APIDOC ## POST /accounts/add-account ### Description Create a new account with default configuration files. ### Method POST ### Endpoint /accounts/add-account ### Parameters #### Query Parameters - **account_name** (string, required) - new account name ### Response #### Success Response (201) `{"message": "Account added successfully."}` #### Error Response (400) Bad Request ``` -------------------------------- ### Get Portfolio State Balances Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieve current balances for specified accounts and connectors. Use `skip_gateway` to speed up by omitting Gateway wallet updates and `refresh` to force a fresh data pull from exchanges. ```json { "accounts": [ { "account_name": "master_account", "connectors": [ { "connector_name": "binance", "tokens": [ {"token": "BTC", "balance": "1.5", "value_usd": "67500"}, {"token": "USDT", "balance": "10000", "value_usd": "10000"} ] } ] } ], "timestamp": "2024-01-10T12:00:00Z" } ``` -------------------------------- ### create_executor Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Creates and starts a new executor for an autonomous strategy. ```APIDOC ## create_executor ### Description Create and start a new executor. ### Method ```python async def create_executor( controller_id: str, connector_name: str, trading_pair: str, config: Dict[str, Any], account_name: str = "master_account", keep_position: bool = False ) -> ExecutorResponse ``` ### Parameters #### Path Parameters - `controller_id` (str) - Required - unique controller identifier - `connector_name` (str) - Required - market connector name - `trading_pair` (str) - Required - trading pair - `config` (Dict[str, Any]) - Required - executor-specific configuration dict - `account_name` (str) - Optional - account to use (defaults to "master_account") - `keep_position` (bool) - Optional - if True, hold position when executor stops (defaults to False) ``` -------------------------------- ### Create Executor Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Creates and starts a new autonomous executor. Specify the controller ID, market details, configuration, and optionally the account and position handling. ```python async def create_executor( controller_id: str, connector_name: str, trading_pair: str, config: Dict[str, Any], account_name: str = "master_account", keep_position: bool = False ) -> ExecutorResponse ``` -------------------------------- ### Get API Version Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Retrieves the current version information of the API. ```APIDOC ## GET /system/version ### Description Get API version information. ### Method GET ### Endpoint /system/version ### Response #### Success Response (200 OK) - `{"version": "1.0.1"}` ### Status Codes - 200 OK ``` -------------------------------- ### Initialize All Trading Connectors Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Asynchronously initializes all configured trading connectors during application startup. Ensures that the OrdersRecorder is attached before any concurrent access occurs. ```python async def initialize_all_trading_connectors() ``` -------------------------------- ### List Gateway Managed Wallets (GET) Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves a list of all wallets managed by the Gateway. The response includes the chain, address, and balance for each wallet. ```python GET /accounts/gateway/wallets Response: Array of wallet objects with `chain`, `address`, `balance` ``` -------------------------------- ### Get Candles Feed Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Retrieves or creates a real-time candles feed. Reuses existing feeds and validates the trading pair. May require waiting for the `.ready` property. ```python async def get_candles_feed(candles_config: CandlesConfig) -> CandlesFeed ``` -------------------------------- ### Get Positions Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Fetches perpetual positions from all configured perpetual connectors. ```APIDOC ## get_positions ### Description Get perpetual positions from all configured perpetual connectors. ### Method `async def get_positions` ### Parameters #### Query Parameters - `account_names` (Optional[List[str]]) - Optional - list of account identifiers - `connector_names` (Optional[List[str]]) - Optional - list of exchange names ### Returns - `List[Dict[str, Any]]` - List of position information. Position fields: account, connector, pair, side, amount, entry_price, unrealized_pnl, leverage, funding_fees ``` -------------------------------- ### FastAPI App and Service Initialization Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md This file is the entry point for the FastAPI application and handles the initialization of core services. ```python main.py # FastAPI app & service initialization ``` -------------------------------- ### Get Trading Connector Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Retrieves or creates an authenticated trading connector for a specific account and connector name. This connector is per-account, fully authenticated, and includes an OrdersRecorder. Raises HTTPException if credentials are not found or initialization fails. ```python async def get_trading_connector( account_name: str, connector_name: str ) -> ConnectorBase ``` -------------------------------- ### Initialize TradingService Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md The constructor requires UnifiedConnectorService and MarketDataService instances. ```python def __init__( connector_service: UnifiedConnectorService, market_data_service: MarketDataService) ``` -------------------------------- ### Configure Gateway Service URL Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md Set the Gateway service URL for DEX interactions. Ensure HTTPS is used for mTLS authentication. Examples show local, Docker Compose, and Tailscale configurations. ```bash # Local development GATEWAY_URL=https://localhost:15888 ``` ```bash # Docker Compose GATEWAY_URL=https://gateway:15888 ``` ```bash # Tailscale remote GATEWAY_URL=https://gateway.tailscale:15888 ``` -------------------------------- ### Get Active Orders Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Retrieves a list of currently active orders. ```APIDOC ## POST /trading/orders/active ### Description Retrieves a list of currently active orders. ### Method POST ### Endpoint /trading/orders/active ### Parameters #### Request Body - **limit** (integer) - Optional - The maximum number of active orders to retrieve. ``` -------------------------------- ### Get System Status Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Retrieves the overall system health and the status of its components. ```APIDOC ## GET /system/status ### Description Get system health and component status. ### Method GET ### Endpoint /system/status ### Response #### Success Response (200 OK) - Component statuses: database, broker, gateway, connectors ### Status Codes - 200 OK ``` -------------------------------- ### Troubleshoot API Startup Source: https://github.com/hummingbot/hummingbot-api/blob/main/README.md Check the logs for the hummingbot-api service to diagnose startup issues. ```bash docker compose logs hummingbot-api ``` -------------------------------- ### Get Real-Time Candles Request Model Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/models-reference.md Use this model to request real-time candles. Requires connector name, trading pair, interval, and an optional max records. ```python class CandlesConfigRequest(BaseModel): connector_name: str trading_pair: str interval: str max_records: int = 100 ``` -------------------------------- ### Get Gateway Status Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Retrieves the current status and health of the Gateway service. ```APIDOC ## GET /gateway/status ### Description Get current Gateway status and health. ### Method GET ### Endpoint /gateway/status ### Response #### Success Response (200 OK) - Status: running/stopped, version, supported chains ### Status Codes - 200 OK ``` -------------------------------- ### Get Specific Bot Status Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves the status of a particular trading bot. ```APIDOC ## GET /bot-orchestration/{bot_name}/status ### Description Get status of a specific bot. ### Method GET ### Endpoint /bot-orchestration/{bot_name}/status ### Parameters #### Path Parameters - **bot_name** (string) - Required - The name of the bot to get the status for. ### Response #### Success Response (200) - **bot_status** (BotStatus) - The status of the specified bot. ``` -------------------------------- ### Get Connector Information Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves detailed information about a specific exchange connector. ```APIDOC ## GET /connectors/{connector_name} ### Description Get detailed connector info. ### Method GET ### Endpoint /connectors/{connector_name} ### Parameters #### Path Parameters - **connector_name** (string) - Required - The name of the connector to retrieve information for. ### Response #### Success Response (200) - **name** (string) - The name of the connector. - **type** (string) - The type of the exchange (e.g., CENTRALIZED_EXCHANGE). - **supported_order_types** (List[string]) - A list of supported order types. - **supported_position_modes** (List[string]) - A list of supported position modes. ### Response Example ```json { "name": "binance", "type": "CENTRALIZED_EXCHANGE", "supported_order_types": ["LIMIT", "MARKET"], "supported_position_modes": ["ONE_WAY", "HEDGE"] } ``` ``` -------------------------------- ### Add New Account (POST) Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Creates a new account. The account name must be a safe filesystem name. Returns a success message upon creation. ```python POST /accounts/add-account Query Parameters: - account_name (required) — new account name Response: {"message": "Account added successfully."} Status: 201 Created Validation: Account names must be safe filesystem names (no special characters). ``` -------------------------------- ### Get Funding Information Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Fetch perpetual funding rates, including the current rate, next funding time, and rate change history for a given trading pair and connector. ```json { "connector_name": "bybit", "trading_pair": "BTC-USDT", "current_rate": "0.0001", "next_funding_time": 1704096000000, "rate_change_history": [...] } ``` -------------------------------- ### Initialize MarketDataService Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Constructor for MarketDataService. Requires a connector service and rate oracle. Optional parameters control feed cleanup and timeout intervals. ```python def __init__(self, connector_service: UnifiedConnectorService, rate_oracle: RateOracle, cleanup_interval: int = 300, feed_timeout: int = 600) ``` -------------------------------- ### Get Specific Connector Information Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Fetches detailed information about a particular exchange connector. ```APIDOC ## GET /connectors/{connector_name} ### Description Get detailed information about a specific connector. ### Method GET ### Endpoint /connectors/{connector_name} ### Parameters #### Path Parameters - **connector_name** (string) - Required - The name of the connector to retrieve information for. ### Response #### Success Response (200 OK) - Connector details: supported pairs, order types, fees, leverage #### Error Response (404 Not Found) - Connector not found. ``` -------------------------------- ### Get Best Connector for Market Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Determines the most suitable connector for a given market, prioritizing trading connectors that already have an order book tracker, and falling back to data-only connectors. Raises an HTTPException if no connector is found. ```python def get_best_connector_for_market( connector_name: str, trading_pair: str ) -> ConnectorBase ``` -------------------------------- ### Manage CLMM Position Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Gets or creates a concentrated liquidity market-making (CLMM) position. ```APIDOC ## POST /gateway/clmm/position ### Description Get or create a concentrated liquidity market-making position. ### Method POST ### Endpoint /gateway/clmm/position ### Parameters #### Request Body - **Position config** - Required - An object with token0, token1, fee_tier, amount0, and amount1. ### Response #### Success Response (200 OK) - **Position details** - An object containing id, liquidity, and range. ### Status Codes - 200 OK - 400 Bad Request - 500 Error ``` -------------------------------- ### Configure MQTT Broker Settings Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md Set MQTT broker connection details and performance dump interval. Use these variables to establish communication between the bot and the API. ```bash BROKER_HOST=emqx BROKER_PORT=1883 BROKER_USERNAME=admin BROKER_PASSWORD=secure-password BROKER_PERFORMANCE_DUMP_INTERVAL=5 ``` -------------------------------- ### Get Latest Controller Performance Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves the latest performance metrics for bot controllers. ```APIDOC ## GET /bot-orchestration/controller-performance-latest ### Description Get latest controller performance metrics. ### Method GET ### Endpoint /bot-orchestration/controller-performance-latest ### Response #### Success Response (200) - **performance_data** (object) - Performance data including execution time, orders, and trades. ``` -------------------------------- ### Get Account Credentials Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Retrieves the connector names for which credentials are configured for a specific account. ```APIDOC ## GET /accounts/{account_name}/credentials ### Description List all connector credentials configured for an account. ### Method GET ### Endpoint /accounts/{account_name}/credentials ### Parameters #### Path Parameters - **account_name** (string, required) - account identifier ### Response #### Success Response (200) `List[str]` — connector names with credentials #### Error Response (404) Not Found ``` -------------------------------- ### Get Trading Pairs for a Connector Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Retrieves all supported trading pairs for a specified exchange connector. ```APIDOC ## GET /connectors/{connector_name}/trading-pairs ### Description Get all supported trading pairs for a connector. ### Method GET ### Endpoint /connectors/{connector_name}/trading-pairs ### Parameters #### Path Parameters - **connector_name** (string) - Required - The name of the connector. ### Response #### Success Response (200 OK) - Array of trading pair strings #### Error Response (404 Not Found) - Connector not found. ``` -------------------------------- ### Get Executor Details Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Fetches detailed information for a specific executor, including its current position. ```python async def get_executor(executor_id: str) -> ExecutorDetailResponse ``` -------------------------------- ### List All Account Names (Bash) Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Use this command to retrieve a list of all account names configured in the system. Requires basic authentication. ```bash curl -u admin:admin http://localhost:8000/accounts # ["master_account", "trading_account"] ``` -------------------------------- ### Get Bot Run History Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves a paginated list of historical bot run records. ```APIDOC ## GET /bot-orchestration/bot-runs ### Description Get bot run history. ### Method GET ### Endpoint /bot-orchestration/bot-runs ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of records to return. - **cursor** (string) - Optional - A cursor for pagination to fetch the next set of records. ### Response #### Success Response (200) - **bot_runs** (PaginatedResponse) - A paginated response containing bot run records. ``` -------------------------------- ### Initialize TradingHistoryService Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Constructor for the TradingHistoryService. Requires an AsyncDatabaseManager instance. ```python def __init__(self, db_manager: AsyncDatabaseManager) ``` -------------------------------- ### Build and Deploy Commands Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md This file contains Makefile targets for common build and deployment tasks. ```makefile Makefile # Build/deploy commands ``` -------------------------------- ### Get Prices Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves the current mid, bid, and ask prices for specified trading pairs. ```APIDOC ## POST /market-data/prices ### Description Get current prices. ### Method POST ### Endpoint /market-data/prices ### Parameters #### Request Body - **connector_name** (string) - Required - The name of the exchange connector. - **trading_pairs** (array) - Required - An array of trading pairs (e.g., ["BTC-USDT", "ETH-USDT"]). ### Response #### Success Response (200) `PricesResponse` object containing prices for each requested trading pair. ### Response Example ```json { "connector_name": "binance", "prices": { "BTC-USDT": {"mid": "45000", "bid": "44999.50", "ask": "45000.50"} } } ``` ``` -------------------------------- ### Get Historical Candles Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves historical candle data within a specified time range. ```APIDOC ## POST /market-data/historical-candles ### Description Get historical candles within a time range. ### Method POST ### Endpoint /market-data/historical-candles ### Parameters #### Request Body - **connector_name** (string) - Required - The name of the exchange connector. - **trading_pair** (string) - Required - The trading pair (e.g., BTC-USDT). - **interval** (string) - Required - The candle interval (e.g., 1m, 5m, 15m, 30m, 1h, 4h, 12h, 1d). - **start_time** (int) - Required - Unix timestamp (ms) for the start of the time range. - **end_time** (int) - Required - Unix timestamp (ms) for the end of the time range. ### Response #### Success Response (200) Array of candle objects. ``` -------------------------------- ### Get Perpetual Positions Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves current perpetual positions, with optional filtering by account and connector. ```APIDOC ## POST /trading/positions ### Description Get perpetual positions. ### Method POST ### Endpoint /trading/positions ### Request Body - **account_names** (array[string], optional) - Filter positions by account names. - **connector_names** (array[string], optional) - Filter positions by connector names. - **limit** (int, optional) - The maximum number of positions to return. - **cursor** (string, optional) - A cursor for pagination, to fetch the next set of results. ### Response #### Success Response - Returns a `PaginatedResponse` object containing position objects. Position fields: - **account_name** (string) - The name of the account. - **connector_name** (string) - The name of the connector. - **trading_pair** (string) - The trading pair. - **side** (string) - The direction of the position (LONG/SHORT). - **amount** (string) - The size of the position. - **entry_price** (string) - The average entry price of the position. - **leverage** (string) - The leverage applied to the position. - **unrealized_pnl** (string) - The unrealized profit or loss. - **margin_ratio** (string) - The margin ratio for the position. - **funding_fees** (string) - The funding fees paid or received. ``` -------------------------------- ### Get Real-Time Candles Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Fetches real-time candle data for a given trading pair and interval. ```APIDOC ## POST /market-data/candles ### Description Fetches real-time candle data for a given trading pair and interval. ### Method POST ### Endpoint /market-data/candles ### Parameters #### Request Body - **connector_name** (string) - Required - The name of the exchange connector. - **trading_pair** (string) - Required - The trading pair (e.g., BTC-USDT). - **interval** (string) - Required - The candle interval (e.g., 1h). - **max_records** (integer) - Optional - The maximum number of candle records to retrieve. ``` -------------------------------- ### Place Order with TradingService Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Use this method to place new orders. Specify account, exchange, trading pair, trade type, amount, and order type. Price is required for limit orders. Position action is used for perpetuals. ```python async def place_order( account_name: str, connector_name: str, trading_pair: str, trade_type: TradeType, amount: Decimal, order_type: OrderType, price: Optional[Decimal] = None, position_action: PositionAction = PositionAction.OPEN ) -> str # returns order_id ``` -------------------------------- ### BotsOrchestrator Constructor Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Initializes the BotsOrchestrator with MQTT broker details, database manager, and optional performance dump interval. ```python def __init__( broker_host: str, broker_port: int, broker_username: str, broker_password: str, db_manager: AsyncDatabaseManager, performance_dump_interval: int = 5) ``` -------------------------------- ### AccountsService Constructor Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Initializes the AccountsService with necessary dependencies and configuration. The account update interval and gateway URL can be customized. ```python def __init__(self, db_manager: AsyncDatabaseManager, connector_service: UnifiedConnectorService, market_data_service: MarketDataService, trading_service: TradingService, account_update_interval: int = 5, gateway_url: str = "https://localhost:15888") ``` -------------------------------- ### API Dockerfile Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Contains instructions for building the Docker image for the Hummingbot API. ```dockerfile Dockerfile # API image ``` -------------------------------- ### Get Available Rate Oracle Sources Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Retrieves a list of all available sources that can be used for rate oracles. ```APIDOC ## GET /rate-oracle/sources ### Description Get available rate oracle sources. ### Method GET ### Endpoint /rate-oracle/sources ### Response #### Success Response (200 OK) - Array of available source names (e.g., `["gate_io", "binance"]`) ``` -------------------------------- ### Get Exchange Rate Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/endpoints.md Retrieves the exchange rate for specified token pairs, useful for portfolio valuation. ```APIDOC ## GET /rate-oracle/rate ### Description Get exchange rate for a token pair (used for portfolio valuation). ### Method GET ### Endpoint /rate-oracle/rate ### Parameters #### Query Parameters - **quote_token** (string) - Optional - Defaults to 'USDT'. The token to price other tokens against. - **tokens** (array of strings) - Required - An array of token symbols for which to get the rates. ### Request Example `GET /rate-oracle/rate?quote_token=USDT&tokens=BTC&tokens=ETH` ### Response #### Success Response (200 OK) - Rates object where keys are token symbols and values are their prices in the `quote_token`. #### Error Response (400 Bad Request) - Invalid query parameters. ``` -------------------------------- ### Create a new account Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Adds a new account to the system. Account names must be safe for filesystem usage. ```APIDOC ## POST /accounts/add-account ### Description Create a new account. ### Method POST ### Endpoint /accounts/add-account ### Parameters #### Query Parameters - **account_name** (string) - Required - The name for the new account. ### Response #### Success Response (201 Created) - **message** (string) - Confirmation message. ``` -------------------------------- ### GatewayService Methods Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Methods for managing the Gateway service startup, stopping, status, and certificate reconciliation. ```APIDOC ## GatewayService ### `start` **Description:** Start the Gateway service via Docker. **Method:** `async def start() -> Dict[str, Any]` **Returns:** Status dict with message and Gateway URL ### `stop` **Description:** Stop the Gateway service. **Method:** `async def stop() -> Dict[str, Any]` ### `status` **Description:** Get current Gateway status and health. **Method:** `async def status() -> Dict[str, Any]` ### `reconcile_certs` **Description:** Verify and reconcile mTLS certificates between API and Gateway. If certs diverge, regenerates and restarts Gateway. **Method:** `def reconcile_certs() -> Dict[str, str]` ``` -------------------------------- ### Get Supported Trading Pairs Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves a list of all trading pairs supported by a specific exchange connector. ```APIDOC ## GET /connectors/{connector_name}/trading-pairs ### Description Get supported trading pairs. ### Method GET ### Endpoint /connectors/{connector_name}/trading-pairs ### Parameters #### Path Parameters - **connector_name** (string) - Required - The name of the connector. ### Response #### Success Response (200) - **trading_pairs** (List[str]) - A list of supported trading pair names. ### Response Example ```json ["BTC-USDT", "ETH-USDT", "BNB-USDT"] ``` ``` -------------------------------- ### Get Funding Info Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves perpetual funding rates and related information for a given trading pair. ```APIDOC ## POST /market-data/funding-info ### Description Get perpetual funding rates. ### Method POST ### Endpoint /market-data/funding-info ### Parameters #### Request Body - **connector_name** (string) - Required - The name of the exchange connector. - **trading_pair** (string) - Required - The trading pair (e.g., BTC-USDT). ### Response #### Success Response (200) `FundingInfoResponse` object containing current rate, next funding time, and rate change history. ### Response Example ```json { "connector_name": "bybit", "trading_pair": "BTC-USDT", "current_rate": "0.0001", "next_funding_time": 1704096000000, "rate_change_history": [...] } ``` ``` -------------------------------- ### Set Application Settings Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md Configure core application behavior by setting environment variables. Use `LOGFIRE_ENVIRONMENT` for logging and `APP_ACCOUNT_UPDATE_INTERVAL` for account update frequency. ```bash LOGFIRE_ENVIRONMENT=prod APP_ACCOUNT_UPDATE_INTERVAL=5 ``` -------------------------------- ### Get Trading Rules for a Pair Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Retrieves the trading rules and constraints for a specific trading pair on an exchange connector. ```APIDOC ## GET /connectors/{connector_name}/trading-rules/{trading_pair} ### Description Get trading rules for a pair. ### Method GET ### Endpoint /connectors/{connector_name}/trading-rules/{trading_pair} ### Parameters #### Path Parameters - **connector_name** (string) - Required - The name of the connector. - **trading_pair** (string) - Required - The trading pair for which to get rules. ### Response #### Success Response (200) - **trading_pair** (string) - The trading pair. - **min_order_size** (string) - The minimum order size. - **max_order_size** (string) - The maximum order size. - **min_price_increment** (string) - The minimum price increment. - **min_base_amount_increment** (string) - The minimum base amount increment. - **min_quote_amount_increment** (string) - The minimum quote amount increment. ### Response Example ```json { "trading_pair": "BTC-USDT", "min_order_size": "0.0001", "max_order_size": "10000", "min_price_increment": "0.01", "min_base_amount_increment": "0.0001", "min_quote_amount_increment": "1" } ``` ``` -------------------------------- ### Load Environment Variables Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md Loads environment variables from a .env file at the project root. This is typically done at application startup. ```bash # Load environment load_dotenv() ``` -------------------------------- ### Get Perpetual Positions Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Fetches perpetual positions. Filter by account names and connector names. Pagination is available. ```json { "account_names": ["master_account"], "connector_names": ["binance"], "limit": 100, "cursor": "" } ``` -------------------------------- ### Enable Tailscale Integration Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/configuration.md Configure Tailscale for secure private networking by setting environment variables in your .env file. Ensure Tailscale is enabled and provide an authentication key and desired hostname. ```bash TAILSCALE_ENABLED=true TAILSCALE_AUTH_KEY=tskey-auth-... TAILSCALE_HOSTNAME=hummingbot-api ``` -------------------------------- ### List All Accounts Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Retrieves a list of all configured accounts. This is useful for understanding the available trading entities. ```bash curl -u admin:admin http://localhost:8000/accounts ``` -------------------------------- ### SwapQuoteRequest Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/models-reference.md Represents a request to get a swap quote. Requires connector name, chain, tokens for swap, and amount. ```APIDOC ## SwapQuoteRequest — Get Swap Quote ### Description Requests a quote for a token swap. ### Request Body - **connector_name** (str) - Required - The name of the DEX connector. - **chain** (str) - Required - The blockchain network. - **token_in** (str) - Required - The token to swap from. - **token_out** (str) - Required - The token to swap to. - **amount_in** (Decimal) - Required - The amount of `token_in` to swap. ``` -------------------------------- ### Set Leverage with TradingService Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/services-architecture.md Configure the leverage for a specific perpetual trading pair on a given account and connector. ```python async def set_leverage( account_name: str, connector_name: str, trading_pair: str, leverage: int ) ``` -------------------------------- ### Get Active Orders Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/README.md Retrieves a list of currently active orders for an account, with an optional limit for the number of results. ```bash curl -u admin:admin -X POST http://localhost:8000/trading/orders/active \ -H "Content-Type: application/json" \ -d '{"limit": 10}' ``` -------------------------------- ### Import and Include Routers in FastAPI App Source: https://github.com/hummingbot/hummingbot-api/blob/main/_autodocs/routers-reference.md Demonstrates how to import various routers and include them in the main FastAPI application instance. Ensure all necessary router modules are imported before inclusion. ```python from routers import ( accounts, archived_bots, backtesting, bot_orchestration, connectors, controllers, docker, executors, gateway, gateway_clmm, gateway_swap, market_data, portfolio, rate_oracle, scripts, storage, system, trading, websocket ) # Included in app app.include_router(accounts.router) app.include_router(trading.router) # ... etc ``` -------------------------------- ### Configure .env for Hummingbot API Source: https://github.com/hummingbot/hummingbot-api/blob/main/README.md Key settings for the Hummingbot API are managed in the .env file. Ensure these are correctly set for API username, password, database connection, and Gateway URL. ```bash USERNAME=admin # API username PASSWORD=admin # API password CONFIG_PASSWORD=admin # Encrypts bot credentials DATABASE_URL=... # PostgreSQL connection GATEWAY_URL=... # Gateway URL (for DEX) # Tailscale (recommended for production) TAILSCALE_ENABLED=true TAILSCALE_AUTH_KEY=tskey-auth-... TAILSCALE_HOSTNAME=hummingbot-api # MagicDNS hostname on your tailnet ```