Skip to content

Commit

Permalink
Merge pull request #49 from hummingbot/feat/adapt_backtesting_engine
Browse files Browse the repository at this point in the history
(feat) use new bt interface
  • Loading branch information
cardosofede authored Nov 27, 2024
2 parents e86e7aa + 6c70c3c commit 9dc6b66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
12 changes: 10 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import HTTPBasic, HTTPBasicCredentials

from routers import manage_accounts, manage_backtesting, manage_broker_messages, manage_docker, manage_files, \
manage_market_data, manage_databases, manage_performance
from routers import (
manage_accounts,
manage_backtesting,
manage_broker_messages,
manage_databases,
manage_docker,
manage_files,
manage_market_data,
manage_performance,
)

load_dotenv()
security = HTTPBasic()
Expand Down
19 changes: 3 additions & 16 deletions routers/manage_backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@
from fastapi import APIRouter
from hummingbot.data_feed.candles_feed.candles_factory import CandlesFactory
from hummingbot.strategy_v2.backtesting.backtesting_engine_base import BacktestingEngineBase
from hummingbot.strategy_v2.backtesting.controllers_backtesting.directional_trading_backtesting import (
DirectionalTradingBacktesting,
)
from hummingbot.strategy_v2.backtesting.controllers_backtesting.market_making_backtesting import MarketMakingBacktesting
from pydantic import BaseModel

from config import CONTROLLERS_MODULE, CONTROLLERS_PATH

router = APIRouter(tags=["Market Backtesting"])
candles_factory = CandlesFactory()
directional_trading_backtesting = DirectionalTradingBacktesting()
market_making_backtesting = MarketMakingBacktesting()

BACKTESTING_ENGINES = {
"directional_trading": directional_trading_backtesting,
"market_making": market_making_backtesting
}
backtesting_engine = BacktestingEngineBase()


class BacktestingConfig(BaseModel):
Expand All @@ -34,19 +24,16 @@ class BacktestingConfig(BaseModel):
async def run_backtesting(backtesting_config: BacktestingConfig):
try:
if isinstance(backtesting_config.config, str):
controller_config = BacktestingEngineBase.get_controller_config_instance_from_yml(
controller_config = backtesting_engine.get_controller_config_instance_from_yml(
config_path=backtesting_config.config,
controllers_conf_dir_path=CONTROLLERS_PATH,
controllers_module=CONTROLLERS_MODULE
)
else:
controller_config = BacktestingEngineBase.get_controller_config_instance_from_dict(
controller_config = backtesting_engine.get_controller_config_instance_from_dict(
config_data=backtesting_config.config,
controllers_module=CONTROLLERS_MODULE
)
backtesting_engine = BACKTESTING_ENGINES.get(controller_config.controller_type)
if not backtesting_engine:
raise ValueError(f"Backtesting engine for controller type {controller_config.controller_type} not found.")
backtesting_results = await backtesting_engine.run_backtesting(
controller_config=controller_config, trade_cost=backtesting_config.trade_cost,
start=int(backtesting_config.start_time), end=int(backtesting_config.end_time),
Expand Down

0 comments on commit 9dc6b66

Please sign in to comment.