Skip to content

Feat/update hummingbot#128

Merged
rapcmia merged 9 commits intomainfrom
feat/update_hummingbot
Feb 25, 2026
Merged

Feat/update hummingbot#128
rapcmia merged 9 commits intomainfrom
feat/update_hummingbot

Conversation

@cardosofede
Copy link
Contributor

@cardosofede cardosofede commented Feb 19, 2026

PR: feat/update_hummingbot

Summary

This PR introduces executor log capture, orphaned executor cleanup on startup, consolidates bot deployment to the controller-based path (removing the legacy script deployment), and adds several new/updated controllers.


Changes

1. Executor Log Capture System (New)

  • New file: utils/executor_log_capture.py - Per-executor log capture using Python contextvars with in-memory ring buffers (50 entries/executor, 200 global).
  • New endpoint: GET /executors/{executor_id}/logs - Retrieve logs for a specific executor with optional level filter and limit.
  • New response fields: error_count and last_error added to ExecutorResponse.
  • New models: ExecutorLogEntry and ExecutorLogsResponse in models/executors.py.
  • Logs are captured from the hummingbot.strategy_v2.executors logger and attributed to executors via ContextVar propagation into spawned asyncio tasks.
  • Logs are cleared automatically when an executor completes.

2. Orphaned Executor Cleanup on Startup

  • New method: ExecutorRepository.cleanup_orphaned_executors() - Bulk-updates DB records stuck in RUNNING status to TERMINATED with close_type=SYSTEM_CLEANUP.
  • New method: ExecutorService.cleanup_orphaned_executors() - Called during app lifespan startup (in main.py) after executor_service.start() and before position recovery.
  • Prevents stale executor records from accumulating after crashes/restarts.

3. Removal of V2 Script Deployment Path

  • Removed: V2ScriptDeployment model from models/bot_orchestration.py.
  • Removed: POST /deploy-v2-script endpoint from routers/bot_orchestration.py.
  • Modified: V2ControllerDeployment now includes script_config: Optional[str] field directly.
  • Modified: DockerService.create_hummingbot_instance() now accepts V2ControllerDeployment instead of V2ScriptDeployment.
  • Docker env var change: HEADLESS renamed to HEADLESS_MODE; CONFIG_FILE_NAME no longer set (only SCRIPT_CONFIG).

4. New & Updated Controllers

New controllers:

  • directional_trading/ai_livestream.py - ML signal-driven directional trading via MQTT
  • directional_trading/bollinger_v2.py - Enhanced Bollinger Bands strategy
  • generic/hedge_asset.py - Asset hedging controller
  • generic/pmm_v1.py - Pure market making v1 (generic)
  • generic/examples/ - 8 example controllers (basic order, open/close, buy three times, candles data, full trading, liquidations monitor, market status, price monitor)

Major updates:

  • generic/pmm_mister.py - Significantly expanded (~1274 lines added)
  • generic/xemm_multiple_levels.py - Cross-exchange market making enhancements
  • generic/stat_arb.py - Statistical arbitrage updates

Cleanup:

  • Removed params_docs/controller_config_template_base.md and params_docs/generic_pmm.md
  • Minor refactors across existing directional trading controllers (bollinger_v1, bollingrid, dman_v3, macd_bb_v1, supertrend_v1)

5. Code Quality

  • Import sorting and organization across main.py, models/__init__.py
  • MQTT manager log level changed from DEBUG to INFO
  • Variable rename l to part in main.py validation handler
  • Docker volume path construction refactored for readability

QA Test Plan

Pre-requisites

  • Backend API running (python main.py)
  • At least one exchange connector configured
  • Docker available for bot deployment tests

Test 1: Executor Log Capture

Step Action Expected Result
1.1 Create an executor (e.g., grid or position executor) Executor created successfully, returns executor ID
1.2 GET /executors/{id} while executor is running Response includes error_count: 0 and last_error: null
1.3 GET /executors/{id}/logs Returns ExecutorLogsResponse with executor_id, logs array, and total_count
1.4 GET /executors/{id}/logs?level=ERROR Returns only ERROR-level log entries (empty if no errors)
1.5 GET /executors/{id}/logs?limit=5 Returns at most 5 log entries
1.6 Stop the executor, then GET /executors/{id}/logs Logs should be cleared (empty array) after executor completion

Test 2: Orphaned Executor Cleanup

Step Action Expected Result
2.1 Create and start an executor Executor running, DB record has status=RUNNING
2.2 Force-kill the API server (simulate crash) Executor record remains RUNNING in DB
2.3 Restart the API server Startup logs show orphaned executor cleanup count
2.4 POST /executors/search with status=TERMINATED Previously orphaned executor now shows status=TERMINATED, close_type=SYSTEM_CLEANUP

Test 3: Bot Deployment (Controller Path Only)

Step Action Expected Result
3.1 POST /deploy-v2-controllers with valid controller config Bot deploys successfully via Docker
3.2 Verify Docker container environment HEADLESS_MODE env var is set (not HEADLESS); SCRIPT_CONFIG is set; no CONFIG_FILE_NAME
3.3 POST /deploy-v2-script (removed endpoint) Returns 404 Not Found or method not allowed

Test 4: Executor Search (Regression)

Step Action Expected Result
4.1 POST /executors/search with no filters Returns combined active (memory) + completed (DB) executors
4.2 POST /executors/search with status=RUNNING Returns only active executors from memory
4.3 POST /executors/search with connector_names filter Returns only executors matching the connector
4.4 Verify error_count and last_error in active executor results Fields present and correctly populated

Test 5: New Controllers Load

Step Action Expected Result
5.1 List available controllers via API New controllers appear: ai_livestream, bollinger_v2, hedge_asset, pmm_v1, all examples
5.2 Create a config for pmm_v1 Config created without errors
5.3 Create a config for pmm_mister (updated) Config created without errors, new parameters accepted

Test 6: API Startup Smoke Test

Step Action Expected Result
6.1 Start the API server No import errors, server starts on expected port
6.2 Check startup logs Orphaned cleanup runs, MQTT logger at INFO level (no DEBUG spam)
6.3 GET /docs (Swagger) All endpoints load, deploy-v2-script is absent, executor/{id}/logs is present

@rapcmia
Copy link
Contributor

rapcmia commented Feb 20, 2026

Commit 9cb71b4

  • Setup on ubuntu24.04 and setup local .whl successfully using development branch
  • Build docker image successfully for hummingbot-api
  • Successfully start hummingbot-api using docker make setup; make deploy

Test in progress

@rapcmia
Copy link
Contributor

rapcmia commented Feb 23, 2026

PR update:

Test Executor Log Capture

  • Create grid executor, (8nruaxzdvRr3CqpFrAZxu2qtFg1s4fhd5nKDCsbcjhDe) ok
  • Get executor by id ok
  • GET /executors/{id}/logs?level=ERROR and GET /executors/{id}/logs?limit=5 both return empty responses ([]) ❌
    • Tested across executors in both RUNNING and TERMINATED states.
    • Tested with extreme total_amount_quote values that triggered runtime error:
      • ERROR - Not enough budget to open position
      • Log routes still returned empty payloads.
    • All log-route endpoint calls returned 200 OK, but captured logs remained empty (logs: [], total_count: 0).
    • Executor stop flow worked successfully.
    • No running executors found via POST /executors/search (and no active executor records observed).

Test Orphaned Executor Cleanup ✅

  • Start grid executor successfully 87zQBificjhWa42Pv9As2mtC9orT873UQZ5kYDrWEf3h
  • Forced stop hummingbot-api using docker kill hummingbot-api
  • Relaunch hummingbot-api successfully
  • Search for the executor id
    curl -sS -u admin:admin -X POST "http://localhost:8000/executors/search" -H "Content-Type: application/json" -d '
    {
      "limit": 1
    }' | jq
    {
      "data": [
        {
          "executor_id": "87zQBificjhWa42Pv9As2mtC9orT873UQZ5kYDrWEf3h",
          "executor_type": "grid_executor",
          "status": "TERMINATED",
          "close_type": "SYSTEM_CLEANUP",
          "connector_name": "kucoin",
          "trading_pair": "SOL-USDT",
          "created_at": "2026-02-23T05:58:56.315437+00:00",
          "closed_at": "2026-02-23T06:02:59.673165+00:00"
        }
      ],
      "pagination": {
        "limit": 1,
        "has_more": true,
        "next_cursor": "87zQBificjhWa42Pv9As2mtC9orT873UQZ5kYDrWEf3h",
        "total_count": 7
      }
    }
    logs: hummingbot-api  | INFO:     172.19.0.1:58004 - "POST /executors/search HTTP/1.1" 200 OK
    
    • Confirmed status is terminated along with closeType.SYSTEM_CLEANUP
      image

Test Bot Deployment (Controller Path Only)

  • Successfully create generic.grid_strike
  • Deploy controller-config and confirmed all the ff is correct:
    • HEADLESS_MODE=true
    • SCRIPT_CONFIG=grid-strike-sol-usdt-20260223-063425.yml
    • CONFIG_FILE_NAME not set
    • This can be check using /bot-orchestration/<container-name>/status
  • On docker logs -f <container_name>, the bot seems active but does not place any orders ❌
    image
    • The config is ok and within grid range but no orders placed
    • I'm able to reproduce this behavior using generic.pmm_V1 as well ❌
    • Use the same config on main branch and able to deploy/start with placing orders ok ✅
    • This blocks tests for New Controllers Load

Test Executor Search (Regression) ✅

  • Based on accumulated test logs
  • POST /executors/search with no filters ok
  • POST /executors/search with status=RUNNING ok
  • POST /executors/search with connector_names filter ok

Pending

  • New Controllers Load

Added test logs: 02232026.zip

@rapcmia
Copy link
Contributor

rapcmia commented Feb 23, 2026

On docker logs -f <container_name>, the bot seems active but does not place any orders ❌

This works now, I overlooked the docker image used on the deployed container was latest instead of development
image


Test in progress

@rapcmia
Copy link
Contributor

rapcmia commented Feb 23, 2026

New Controllers Load

  • List available controllers by type using ./controllers/ route
    • includes ai_livestream, pmm_v1, pmm_mister and bollinger_v2
  • Check all config templates ok
    • However the generic.pmm_mister.py fails with err Controller configuration class for 'pmm_mister' not found"
      curl -sS -u admin:admin "http://localhost:8000/controllers/generic/pmm_mister/config/template" | jq
      {
        "detail": "Controller configuration class for 'pmm_mister' not found"
      }
      logs: hummingbot-api  | INFO:     172.19.0.1:53504 - "GET /controllers/generic/pmm_mister/config/template HTTP/1.1" 404 Not Found
      
      • Confirmed with dev that there was changes on the pmm_mister controller-config now only use one price distance parameter
      • Observed error on logs
        2026-02-23 15:03:16,936 - utils.file_system - WARNING - Error loading controller class for 'generic.pmm_mister': cannot import name 'parse_comma_separated_list' from 'hummingbot.strategy_v2.utils.common' (/opt/conda/envs/hummingbot-api/lib/python3.12/site-packages/hummingbot/strategy_v2/utils/common.py)
        

@rapcmia
Copy link
Contributor

rapcmia commented Feb 23, 2026

Commit 9681033

However the generic.pmm_mister.py fails with err Controller configuration class for 'pmm_mister' not found" ❌

  • Fixed controller/generic/pmm_mister/confi/template ✅
    curl -sS -u admin:admin "http://localhost:8000/controllers/generic/pmm_mister/config/template" | jq
    {
      "controller_name": {
        "default": "pmm_mister"
      },
      "controller_type": {
        "default": "generic"
      },
      "connector_name": {
        "default": "binance"
      },
      "trading_pair": {
        "default": "BTC-FDUSD"
      },
      "total_amount_quote": {
        "default": "100"
      },
      "portfolio_allocation": {
        "default": "0.1"
      },
      "buy_spreads": {
        "default": "0.0005"
      },
      "sell_spreads": {
        "default": "0.0005"
      }
    }
    logs: hummingbot-api  | INFO:     172.19.0.1:54998 - "GET /controllers/generic/pmm_mister/config/template HTTP/1.1" 200 OK
    
  • Successfully deploy and start controller-config and check exchange order activity
    image

GET /executors/{id}/logs?level=ERROR and GET /executors/{id}/logs?limit=5 both return empty responses ([]) ❌

  • Successfully started grid executor with low order amount to trigger min notional and not enough balance behavior/error ✅
  • Recheck executor logs by id (level=ERROR)
    curl -sS -u admin:admin "http://localhost:8000/executors/2GtEvZNtMtacNPpBJTQy6KqnAdXAGu2KQjdV6QVQEavZ/logs?level=ERROR" | jq
    {
      "executor_id": "2GtEvZNtMtacNPpBJTQy6KqnAdXAGu2KQjdV6QVQEavZ",
      "logs": [
        {
          "level": "ERROR",
          "message": "hummingbot.strategy_v2.executors.grid_executor.grid_executor - Not enough budget to open position."
        },
        {
          "level": "ERROR",
          "message": "hummingbot.strategy_v2.executors.grid_executor.grid_executor - Grid is already expired by CloseType.STOP_LOSS."
        }
      ],
      "total_count": 2
    }
    logs: hummingbot-api  | INFO:     172.19.0.1:54896 - "GET /executors/2GtEvZNtMtacNPpBJTQy6KqnAdXAGu2KQjdV6QVQEavZ/logs?level=ERROR HTTP/1.1" 200 OK
    
  • Recheck executor logs by id (limit=5)
    curl -sS -u admin:admin "http://localhost:8000/executors/2GtEvZNtMtacNPpBJTQy6KqnAdXAGu2KQjdV6QVQEavZ/logs?limit=5" | jq
    {
      "executor_id": "2GtEvZNtMtacNPpBJTQy6KqnAdXAGu2KQjdV6QVQEavZ",
      "logs": [
        {
          "level": "ERROR",
          "message": "hummingbot.strategy_v2.executors.grid_executor.grid_executor - Not enough budget to open position."
        },
        {
          "level": "ERROR",
          "message": "hummingbot.strategy_v2.executors.grid_executor.grid_executor - Grid is already expired by CloseType.STOP_LOSS."
        }
      ],
      "total_count": 2
    }
    logs: hummingbot-api  | INFO:     172.19.0.1:54904 - "GET /executors/2GtEvZNtMtacNPpBJTQy6KqnAdXAGu2KQjdV6QVQEavZ/logs?limit=5 HTTP/1.1" 200 OK
    

Test archive and logs: 02242026.zip


Preparing test summary

Copy link
Contributor

@rapcmia rapcmia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Setup on ubuntu24.04 on docker build
  • Create local hummingbot-lib and successfully build docker image with this PR
  • Use make setup; make deploy
  • Successfully started hummingbot-api and focused on testing routes
  • Executor log capture ✅
    • Successfully started grid executor with low order size
    • GET /executor//logs?level=ERROR and LIMIT=5
  • Orphaned Executor Cleanup ✅
    • Start a grid executor again then forced exit hummingbot-api using docker kill <..>
    • Relaunch hummingbot-api and check executor status using routes and DB
    • Executor tagged as TERMINATED by SYSTEM_CLEANUP
  • Bot Deployment (Controller Path Only) ✅
    • Successfully created controllers for generic.{grid_strike, pmm_v1 and pmm_mister}
    • Deploy and start bot:
      • By default, headless is false
      • If user wants headless mode, include headless: truein:
        • POST /bot-orchestration/deploy-v2-controllers
      • Confirmed that SCRIPT_CONFIG is set, no CONFIG_FILE_NAME
    • Successsfuly archived bots
  • Executor Search (Regression) ✅
    • Based on accumulated test logs
    • POST /executors/search with no filters ok
    • POST /executors/search with status=RUNNING ok
    • POST /executors/search with connector_names filter ok
  • Issues reported to dev has been fixed

@rapcmia rapcmia merged commit dbcef3d into main Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants