Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) use new bt interface #49

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 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 Expand Up @@ -47,3 +55,4 @@ def auth_user(
app.include_router(manage_backtesting.router, dependencies=[Depends(auth_user)])
app.include_router(manage_databases.router, dependencies=[Depends(auth_user)])
app.include_router(manage_performance.router, dependencies=[Depends(auth_user)])
app.include_router(manage_accounts.router, dependencies=[Depends(auth_user)])
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