feat: instrument model
This commit is contained in:
@@ -148,6 +148,43 @@ def apply_gauge_suggestions(
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.get("/{instrument}/macro-sync")
|
||||
def get_macro_sync(instrument: str) -> Dict[str, Any]:
|
||||
"""Retourne les valeurs actuelles + forecasts FF Calendar pour tous les nœuds macro-liés."""
|
||||
from services.database import get_conn
|
||||
from services.instrument_models import get_macro_sync_items
|
||||
conn = get_conn()
|
||||
try:
|
||||
items = get_macro_sync_items(conn, instrument)
|
||||
return {"instrument": instrument.upper(), "items": items, "count": len(items)}
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
class MacroSyncApplyBody(BaseModel):
|
||||
items: list[dict] # [{node_id, value, note}]
|
||||
|
||||
@router.post("/{instrument}/macro-sync/apply")
|
||||
def apply_macro_sync(instrument: str, body: MacroSyncApplyBody) -> Dict[str, Any]:
|
||||
"""Applique les valeurs macro (actuelles ou forecasts) comme node overrides."""
|
||||
from services.database import get_conn
|
||||
from services.instrument_models import set_node_override
|
||||
conn = get_conn()
|
||||
try:
|
||||
inst = instrument.upper()
|
||||
saved = []
|
||||
for item in body.items:
|
||||
nid = item.get("node_id", "")
|
||||
value = item.get("value")
|
||||
note = item.get("note", "[Sync Marché FF Calendar]")
|
||||
if nid and value is not None:
|
||||
set_node_override(conn, inst, nid, float(value), note)
|
||||
saved.append(nid)
|
||||
return {"ok": True, "instrument": inst, "saved": saved, "count": len(saved)}
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.delete("/{instrument}/overrides")
|
||||
def clear_all_overrides(instrument: str) -> Dict[str, Any]:
|
||||
"""Supprime TOUTES les overrides d'un instrument (reset à zéro)."""
|
||||
|
||||
Reference in New Issue
Block a user