mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
docs: update API docs for async download behavior
Document: - New downloading_data status - Warnings field in responses - Async flow and monitoring - Example usage patterns Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -269,12 +269,14 @@ Get status and progress of a simulation job.
|
|||||||
| `total_duration_seconds` | float | Total execution time in seconds |
|
| `total_duration_seconds` | float | Total execution time in seconds |
|
||||||
| `error` | string | Error message if job failed |
|
| `error` | string | Error message if job failed |
|
||||||
| `details` | array[object] | Per model-day execution details |
|
| `details` | array[object] | Per model-day execution details |
|
||||||
|
| `warnings` | array[string] | Optional array of non-fatal warning messages |
|
||||||
|
|
||||||
**Job Status Values:**
|
**Job Status Values:**
|
||||||
|
|
||||||
| Status | Description |
|
| Status | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| `pending` | Job created, waiting to start |
|
| `pending` | Job created, waiting to start |
|
||||||
|
| `downloading_data` | Preparing price data (downloading if needed) |
|
||||||
| `running` | Job currently executing |
|
| `running` | Job currently executing |
|
||||||
| `completed` | All model-days completed successfully |
|
| `completed` | All model-days completed successfully |
|
||||||
| `partial` | Some model-days completed, some failed |
|
| `partial` | Some model-days completed, some failed |
|
||||||
@@ -289,6 +291,35 @@ Get status and progress of a simulation job.
|
|||||||
| `completed` | Finished successfully |
|
| `completed` | Finished successfully |
|
||||||
| `failed` | Execution failed (see `error` field) |
|
| `failed` | Execution failed (see `error` field) |
|
||||||
|
|
||||||
|
**Warnings Field:**
|
||||||
|
|
||||||
|
The optional `warnings` array contains non-fatal warning messages about the job execution:
|
||||||
|
|
||||||
|
- **Rate limit warnings**: Price data download hit API rate limits
|
||||||
|
- **Skipped dates**: Some dates couldn't be processed due to incomplete price data
|
||||||
|
- **Other issues**: Non-fatal problems that don't prevent job completion
|
||||||
|
|
||||||
|
**Example response with warnings:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"job_id": "019a426b-1234-5678-90ab-cdef12345678",
|
||||||
|
"status": "completed",
|
||||||
|
"progress": {
|
||||||
|
"total_model_days": 10,
|
||||||
|
"completed": 8,
|
||||||
|
"failed": 0,
|
||||||
|
"pending": 0
|
||||||
|
},
|
||||||
|
"warnings": [
|
||||||
|
"Rate limit reached - downloaded 12/15 symbols",
|
||||||
|
"Skipped 2 dates due to incomplete price data: ['2025-10-02', '2025-10-05']"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If no warnings occurred, the field will be `null` or omitted.
|
||||||
|
|
||||||
**Error Response:**
|
**Error Response:**
|
||||||
|
|
||||||
**404 Not Found** - Job doesn't exist
|
**404 Not Found** - Job doesn't exist
|
||||||
|
|||||||
@@ -94,6 +94,70 @@ curl "http://localhost:8080/results?job_id=$JOB_ID&date=2025-01-16&model=gpt-4"
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Async Data Download
|
||||||
|
|
||||||
|
The `/simulate/trigger` endpoint responds immediately (<1 second), even when price data needs to be downloaded.
|
||||||
|
|
||||||
|
### Flow
|
||||||
|
|
||||||
|
1. **POST /simulate/trigger** - Returns `job_id` immediately
|
||||||
|
2. **Background worker** - Downloads missing data automatically
|
||||||
|
3. **Poll /simulate/status** - Track progress through status transitions
|
||||||
|
|
||||||
|
### Status Progression
|
||||||
|
|
||||||
|
```
|
||||||
|
pending → downloading_data → running → completed
|
||||||
|
```
|
||||||
|
|
||||||
|
### Monitoring Progress
|
||||||
|
|
||||||
|
Use `docker logs -f` to monitor download progress in real-time:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker logs -f ai-trader-server
|
||||||
|
|
||||||
|
# Example output:
|
||||||
|
# Job 019a426b: Checking price data availability...
|
||||||
|
# Job 019a426b: Missing data for 15 symbols
|
||||||
|
# Job 019a426b: Starting prioritized download...
|
||||||
|
# Job 019a426b: Download complete - 12/15 symbols succeeded
|
||||||
|
# Job 019a426b: Rate limit reached - proceeding with available dates
|
||||||
|
# Job 019a426b: Starting execution - 8 dates, 1 models
|
||||||
|
```
|
||||||
|
|
||||||
|
### Handling Warnings
|
||||||
|
|
||||||
|
Check the `warnings` field in status response:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Trigger simulation
|
||||||
|
response = requests.post("http://localhost:8080/simulate/trigger", json={
|
||||||
|
"start_date": "2025-10-01",
|
||||||
|
"end_date": "2025-10-10",
|
||||||
|
"models": ["gpt-5"]
|
||||||
|
})
|
||||||
|
|
||||||
|
job_id = response.json()["job_id"]
|
||||||
|
|
||||||
|
# Poll until complete
|
||||||
|
while True:
|
||||||
|
status = requests.get(f"http://localhost:8080/simulate/status/{job_id}").json()
|
||||||
|
|
||||||
|
if status["status"] in ["completed", "partial", "failed"]:
|
||||||
|
# Check for warnings
|
||||||
|
if status.get("warnings"):
|
||||||
|
print("Warnings:", status["warnings"])
|
||||||
|
break
|
||||||
|
|
||||||
|
time.sleep(2)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
### 1. Check Health Before Triggering
|
### 1. Check Health Before Triggering
|
||||||
|
|||||||
Reference in New Issue
Block a user