Refactor raw trade management and enhance database operations

- Removed the `RawDataManager` class and integrated its functionality directly into the `RawTradeRepository`, streamlining the management of raw trade data.
- Implemented the `cleanup_old_raw_data` method to delete outdated records, preventing table bloat and improving performance.
- Added the `get_raw_data_stats` method to retrieve statistics about raw data storage, enhancing data management capabilities.
- Updated documentation to reflect the new methods and their usage, ensuring clarity for future developers.

These changes improve the maintainability and efficiency of the database operations related to raw trade data.
This commit is contained in:
Vasily.onl
2025-06-06 23:51:21 +08:00
parent b30c16bc33
commit 1466223b85
4 changed files with 82 additions and 435 deletions

View File

@@ -342,6 +342,33 @@ trades = db.raw_trades.get_raw_trades(
)
```
##### `cleanup_old_raw_data(days_to_keep: int = 7) -> int`
Clean up old raw data to prevent table bloat.
**Parameters:**
- `days_to_keep`: Number of days to retain raw data records.
**Returns:** The number of records deleted.
```python
# Clean up raw data older than 14 days
deleted_count = db.raw_trades.cleanup_old_raw_data(days_to_keep=14)
print(f"Deleted {deleted_count} old raw data records.")
```
##### `get_raw_data_stats() -> Dict[str, Any]`
Get statistics about raw data storage.
**Returns:** A dictionary with statistics like total records, table size, etc.
```python
raw_stats = db.raw_trades.get_raw_data_stats()
print(f"Raw Trades Table Size: {raw_stats.get('table_size')}")
print(f"Total Raw Records: {raw_stats.get('total_records')}")
```
## Error Handling
The database operations module includes comprehensive error handling with custom exceptions.