Skip to content

Commit 6a488a9

Browse files
morteza-koohgardsaleh-mir
authored andcommitted
Add endpoint to retrieve backtest logs by session ID
1 parent d72e275 commit 6a488a9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

jesse/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,5 +657,28 @@ def delete_candles(json_request: DeleteCandlesRequestJson, authorization: Option
657657
except Exception as e:
658658
return JSONResponse({'error': str(e)}, status_code=500)
659659

660+
661+
@fastapi_app.get("/logs/backtest/{session_id}")
662+
def get_logs(session_id: str, token: str = Query(...)):
663+
"""
664+
Get logs as text for a specific session. Similar to download but returns text content instead of file.
665+
"""
666+
if not authenticator.is_valid_token(token):
667+
return authenticator.unauthorized_response()
668+
669+
try:
670+
path = f'storage/logs/backtest-mode/{session_id}.txt'
671+
672+
if not os.path.exists(path):
673+
return JSONResponse({'error': 'Log file not found'}, status_code=404)
674+
675+
with open(path, 'r') as f:
676+
content = f.read()
677+
678+
return JSONResponse({'content': content}, status_code=200)
679+
except Exception as e:
680+
return JSONResponse({'error': str(e)}, status_code=500)
681+
682+
660683
# Mount static files.Must be loaded at the end to prevent overlapping with API endpoints
661684
fastapi_app.mount("/", StaticFiles(directory=f"{JESSE_DIR}/static"), name="static")

0 commit comments

Comments
 (0)