28 lines
903 B
Python
28 lines
903 B
Python
from __future__ import annotations
|
|
|
|
from typing import Protocol
|
|
|
|
from app.models.portfolio import PortfolioConfig
|
|
|
|
|
|
class _SaveStatusConfig(Protocol):
|
|
entry_basis_mode: str
|
|
gold_value: float | None
|
|
entry_price: float | None
|
|
gold_ounces: float | None
|
|
current_ltv: float
|
|
margin_call_price: object
|
|
|
|
|
|
def margin_call_price_value(config: PortfolioConfig | _SaveStatusConfig) -> float:
|
|
margin_call_price = config.margin_call_price
|
|
return float(margin_call_price() if callable(margin_call_price) else margin_call_price)
|
|
|
|
|
|
def save_status_text(config: PortfolioConfig | _SaveStatusConfig) -> str:
|
|
return (
|
|
f"Saved: basis={config.entry_basis_mode}, start=${config.gold_value:,.0f}, "
|
|
f"entry=${config.entry_price:,.2f}/oz, weight={config.gold_ounces:,.2f} oz, "
|
|
f"LTV={config.current_ltv:.1%}, trigger=${margin_call_price_value(config):,.2f}/oz"
|
|
)
|