fix: harden Structural S/R after OHLCV writes and surface cleanup failures
Honor custom S/R tolerance as a transient detect, refresh levels after OHLCV mutations without failing committed price writes, report per-ticker S/R rebuild failures from admin cleanup, and warn in the admin UI when refresh is partial.
This commit is contained in:
@@ -19,6 +19,7 @@ from app.dependencies import get_db, require_access
|
||||
from app.exceptions import ProviderError
|
||||
from app.models.ohlcv import OHLCVRecord
|
||||
from app.models.settings import IngestionProgress
|
||||
from app.models.sr_level import SRLevel
|
||||
from app.models.ticker import Ticker
|
||||
from app.models.user import User
|
||||
from app.providers.alpaca import AlpacaOHLCVProvider
|
||||
@@ -105,8 +106,13 @@ async def fetch_symbol(
|
||||
await db.execute(
|
||||
delete(IngestionProgress).where(IngestionProgress.ticker_id == ticker_obj.id)
|
||||
)
|
||||
# Drop Structural S/R with the bars; a failed re-fetch must not
|
||||
# leave zones computed from deleted history.
|
||||
await db.execute(
|
||||
delete(SRLevel).where(SRLevel.ticker_id == ticker_obj.id)
|
||||
)
|
||||
await db.commit()
|
||||
logger.info("force_refetch: cleared OHLCV and progress for %s", symbol_upper)
|
||||
logger.info("force_refetch: cleared OHLCV, S/R, and progress for %s", symbol_upper)
|
||||
except Exception as exc:
|
||||
logger.error("force_refetch cleanup failed for %s: %s", symbol_upper, exc)
|
||||
|
||||
|
||||
@@ -74,7 +74,11 @@ async def read_sr_levels(
|
||||
None,
|
||||
ge=0,
|
||||
le=0.1,
|
||||
description="Merge tolerance as fraction of price; omit for ATR-adaptive default",
|
||||
description=(
|
||||
"Merge tolerance as fraction of price. Omit to return persisted levels "
|
||||
"(ATR-adaptive at last recalculation). When set, returns a transient "
|
||||
"detect with this tolerance (not written to the DB)."
|
||||
),
|
||||
),
|
||||
max_zones: int = Query(6, ge=0, description="Max S/R zones to return (default 6)"),
|
||||
_user=Depends(require_access),
|
||||
|
||||
Reference in New Issue
Block a user