-
Notifications
You must be signed in to change notification settings - Fork 76
Feat/performance page endpoints #36
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
Merged
cardosofede
merged 25 commits into
hummingbot:main
from
tomasgaudino:feat/performance-page-endpoints
Nov 16, 2024
Merged
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
03b481d
(feat) add database endpoints
tomasgaudino 14068e7
(feat) add checkpoint management endpoints + add controllers table to…
tomasgaudino ceb0f5b
(feat) load controllers
tomasgaudino 5fdbaba
(feat) add performance endpoints
tomasgaudino 503c86e
(feat) improve etl performance + remove controller type from performa…
tomasgaudino c121170
(feat) replace unpacking method by dict definition for executor info …
tomasgaudino 8e15d7b
Update Makefile
david-hummingbot 1ab63e7
fix-conda-env
david-hummingbot 90b7366
update python-multipart version
david-hummingbot b286bc1
(feat) add logfire dependency
cardosofede 2d9a462
(feat) add logfire config
cardosofede 2d7b6d0
(feat) add connector name to the logs
cardosofede 790d300
(feat) add user and pass for the api
cardosofede f1341c5
(feat) add grid strike
cardosofede e98e77c
(feat) update environment
cardosofede 197dac7
(feat) add security
cardosofede 353ee91
(fix) typo
cardosofede 6364add
(feat) add database endpoints
tomasgaudino f232b1a
(feat) add performance endpoints
tomasgaudino 86f405d
(fix) fix main
tomasgaudino 08760f3
Merge branch 'main' into feat/performance-page-endpoints
tomasgaudino 9bf3bd7
(fix) remove * from .gitignore
tomasgaudino 2dbaa17
(feat) add lost lines from bad github management
tomasgaudino 23c0286
(feat) add debug mode
tomasgaudino 394d6ec
(feat) update compose file
tomasgaudino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import json | ||
import time | ||
|
||
from typing import List, Dict, Any | ||
|
||
import pandas as pd | ||
|
||
from utils.etl_databases import HummingbotDatabase, ETLPerformance | ||
from fastapi import APIRouter | ||
|
||
from utils.file_system import FileSystemUtil | ||
|
||
router = APIRouter(tags=["Database Management"]) | ||
file_system = FileSystemUtil() | ||
|
||
|
||
@router.post("/list-databases", response_model=List[str]) | ||
async def list_databases(): | ||
return file_system.list_databases() | ||
|
||
|
||
@router.post("/read-databases", response_model=List[Dict[str, Any]]) | ||
async def read_databases(db_paths: List[str] = None): | ||
dbs = [] | ||
for db_path in db_paths: | ||
db = HummingbotDatabase(db_path) | ||
try: | ||
db_content = { | ||
"db_name": db.db_name, | ||
"db_path": db.db_path, | ||
"healthy": db.status["general_status"], | ||
"status": db.status, | ||
"tables": { | ||
"orders": json.dumps(db.get_orders().to_dict()), | ||
"trade_fill": json.dumps(db.get_trade_fills().to_dict()), | ||
"executors": json.dumps(db.get_executors_data().to_dict()), | ||
"order_status": json.dumps(db.get_order_status().to_dict()), | ||
"controllers": json.dumps(db.get_controllers_data().to_dict()) | ||
} | ||
} | ||
except Exception as e: | ||
print(f"Error reading database {db_path}: {str(e)}") | ||
db_content = { | ||
"db_name": "", | ||
"db_path": db_path, | ||
"healthy": False, | ||
"status": db.status, | ||
"tables": {} | ||
} | ||
dbs.append(db_content) | ||
return dbs | ||
|
||
|
||
@router.post("/create-checkpoint", response_model=Dict[str, Any]) | ||
async def create_checkpoint(db_paths: List[str]): | ||
try: | ||
dbs = await read_databases(db_paths) | ||
|
||
healthy_dbs = [db for db in dbs if db["healthy"]] | ||
|
||
table_names = ["trade_fill", "orders", "order_status", "executors", "controllers"] | ||
tables_dict = {name: pd.DataFrame() for name in table_names} | ||
|
||
for db in healthy_dbs: | ||
for table_name in table_names: | ||
new_data = pd.DataFrame(json.loads(db["tables"][table_name])) | ||
new_data["db_path"] = db["db_path"] | ||
new_data["db_name"] = db["db_name"] | ||
tables_dict[table_name] = pd.concat([tables_dict[table_name], new_data]) | ||
|
||
etl = ETLPerformance(db_path=f"bots/data/checkpoint_{str(int(time.time()))}.sqlite") | ||
etl.create_tables() | ||
etl.insert_data(tables_dict) | ||
return {"message": "Checkpoint created successfully."} | ||
except Exception as e: | ||
return {"message": f"Error: {str(e)}"} | ||
|
||
|
||
@router.post("/list-checkpoints", response_model=List[str]) | ||
async def list_checkpoints(full_path: bool): | ||
return file_system.list_checkpoints(full_path) | ||
|
||
|
||
@router.post("/load-checkpoint") | ||
async def load_checkpoint(checkpoint_path: str): | ||
try: | ||
etl = ETLPerformance(checkpoint_path) | ||
executor = etl.load_executors() | ||
order = etl.load_orders() | ||
trade_fill = etl.load_trade_fill() | ||
controllers = etl.load_controllers() | ||
checkpoint_data = { | ||
"executors": json.dumps(executor.to_dict()), | ||
"orders": json.dumps(order.to_dict()), | ||
"trade_fill": json.dumps(trade_fill.to_dict()), | ||
"controllers": json.dumps(controllers.to_dict()) | ||
} | ||
return checkpoint_data | ||
except Exception as e: | ||
return {"message": f"Error: {str(e)}"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from fastapi import APIRouter | ||
from typing import Any, Dict | ||
|
||
from hummingbot.strategy_v2.backtesting.backtesting_engine_base import BacktestingEngineBase | ||
|
||
from utils.etl_databases import PerformanceDataSource | ||
|
||
router = APIRouter(tags=["Market Performance"]) | ||
|
||
|
||
@router.post("/get-performance-results") | ||
async def get_performance_results(payload: Dict[str, Any]): | ||
executors = payload.get("executors") | ||
data_source = PerformanceDataSource(executors) | ||
performance_results = {} | ||
try: | ||
backtesting_engine = BacktestingEngineBase() | ||
executor_info_list = data_source.executor_info_list | ||
performance_results["results"] = backtesting_engine.summarize_results(executor_info_list ) | ||
results = performance_results["results"] | ||
results["sharpe_ratio"] = results["sharpe_ratio"] if results["sharpe_ratio"] is not None else 0 | ||
return { | ||
"executors": executors, | ||
"results": performance_results["results"], | ||
} | ||
|
||
except Exception as e: | ||
return {"error": str(e)} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.