/
SimpleSpace
/
AutoInvestDataSync
Обзор
Документация
Войти
/
SimpleSpace
/
AutoInvestDataSync
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
sync/history.py
39 строк
1 KB
Alex Just
Start commit for mvp 0.0.5 version
04 май 2026, 22:47
04 май 2026, 22:47
e12863e
Код
Авторство
О чём код?
from __future__ import annotations import os import logging from datetime import datetime import yaml logger = logging.getLogger(__name__) def load_history(filepath: str) -> list[dict]: if not os.path.exists(filepath): return [] try: with open(filepath, "r", encoding="utf-8") as f: data = yaml.safe_load(f) return data if isinstance(data, list) else [] except Exception as e: logger.warning("Failed to load capital history: %s", e) return [] def save_history(filepath: str, history: list[dict]) -> None: os.makedirs(os.path.dirname(filepath) or ".", exist_ok=True) with open(filepath, "w", encoding="utf-8") as f: yaml.dump(history, f, default_flow_style=False, allow_unicode=True) def add_history_entry(filepath: str, buy_value: float, current_value: float) -> list[dict]: history = load_history(filepath) entry = { "date": datetime.now().strftime("%Y-%m-%d %H:%M"), "buy_value": round(buy_value, 2), "current_value": round(current_value, 2), } history.append(entry) save_history(filepath, history) return history