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/enhance controllers configs management #15

Merged
merged 15 commits into from
Jun 21, 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
3 changes: 2 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
BROKER_PORT = int(os.getenv("BROKER_PORT", 1883))
BROKER_USERNAME = os.getenv("BROKER_USERNAME", "admin")
BROKER_PASSWORD = os.getenv("BROKER_PASSWORD", "password")
PASSWORD_VERIFICATION_PATH = "bots/credentials/master_account/.password_verification"
PASSWORD_VERIFICATION_PATH = "bots/credentials/master_account/.password_verification"
BANNED_TOKENS = os.getenv("BANNED_TOKENS", "NAV,ARS,ETHW").split(",")
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- pip
- pip:
- hummingbot
- numpy==1.26.4
# - docker
- git+https://github.com/felixfontein/docker-py
- python-dotenv
Expand Down
28 changes: 21 additions & 7 deletions routers/manage_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
# Initialize the scheduler
scheduler = AsyncIOScheduler()
router = APIRouter(tags=["Manage Credentials"])
file_system = FileSystemUtil()
file_system = FileSystemUtil(base_path="bots/credentials")
accounts_service = AccountsService()


@router.on_event("startup")
async def startup_event():
# Add the job to the scheduler
scheduler.start()
accounts_service.start_update_balances_loop()
accounts_service.start_update_account_state_loop()


@router.on_event("shutdown")
Expand All @@ -28,9 +28,21 @@ async def shutdown_event():
scheduler.shutdown()


@router.get("/get-all-balances", response_model=Dict[str, Dict[str, Dict[str, float]]])
async def get_all_balances():
return accounts_service.get_all_balances()
@router.get("/accounts-state", response_model=Dict[str, Dict[str, List[Dict]]])
async def get_all_accounts_state():
return accounts_service.get_accounts_state()


@router.get("/account-state-history", response_model=List[Dict])
async def get_account_state_history():
"""
Get the historical state of all accounts.
"""
try:
history = accounts_service.load_account_state_history()
return history
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))


@router.get("/available-connectors", response_model=List[str])
Expand All @@ -42,6 +54,7 @@ async def available_connectors():
async def get_connector_config_map(connector_name: str):
return accounts_service.get_connector_config_map(connector_name)


@router.get("/all-connectors-config-map", response_model=Dict[str, List[str]])
async def get_all_connectors_config_map():
all_config_maps = {}
Expand Down Expand Up @@ -95,7 +108,8 @@ async def delete_credential(account_name: str, connector_name: str):
@router.post("/add-connector-keys/{account_name}/{connector_name}", status_code=status.HTTP_201_CREATED)
async def add_connector_keys(account_name: str, connector_name: str, keys: Dict):
try:
accounts_service.add_connector_keys(account_name, connector_name, keys)
await accounts_service.add_connector_keys(account_name, connector_name, keys)
return {"message": "Connector keys added successfully."}
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
accounts_service.delete_credentials(account_name, connector_name)
raise HTTPException(status_code=400, detail=str(e))
10 changes: 9 additions & 1 deletion routers/manage_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ async def update_controller_config(bot_name: str, controller_id: str, config: Di
return {"message": "Controller configuration updated successfully."}



@router.post("/add-script", status_code=status.HTTP_201_CREATED)
async def add_script(script: Script, override: bool = False):
try:
Expand Down Expand Up @@ -140,6 +139,7 @@ async def add_controller_config(config: ScriptConfig):
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))


@router.post("/upload-controller-config")
async def upload_controller_config(config_file: UploadFile = File(...), override: bool = False):
try:
Expand All @@ -149,3 +149,11 @@ async def upload_controller_config(config_file: UploadFile = File(...), override
except FileExistsError as e:
raise HTTPException(status_code=400, detail=str(e))


@router.post("/delete-controller-config", status_code=status.HTTP_200_OK)
async def delete_controller_config(config_name: str):
try:
file_system.delete_file('conf/controllers', config_name)
return {"message": f"Controller configuration {config_name} deleted successfully."}
except FileNotFoundError as e:
raise HTTPException(status_code=404, detail=str(e))
Loading