fix: align research metadata with live WorldQuant responses
This commit is contained in:
@@ -70,8 +70,16 @@ def setting_rows(data):
|
||||
raise HTTPException(502, "平台设置结构无法识别,未发布新快照") from None
|
||||
|
||||
|
||||
def normalize_availability(data):
|
||||
def normalize_availability(data, *, instrument_type=None):
|
||||
"""Use the request's instrument only for the platform field-detail `data` form.
|
||||
|
||||
Legacy availability rows must still state their own instrument. Missing market,
|
||||
delay or universe never inherits the requested scope.
|
||||
"""
|
||||
raw = data.get("availability")
|
||||
detail_form = raw is None and isinstance(data.get("data"), list)
|
||||
if detail_form:
|
||||
raw = data["data"]
|
||||
if not isinstance(raw, list):
|
||||
return {"status": "needs_review", "items": [], "reason": "平台未提供可识别的 availability 列表"}
|
||||
rows, malformed = [], False
|
||||
@@ -83,7 +91,7 @@ def normalize_availability(data):
|
||||
universes = universes if isinstance(universes, list) else [universes]
|
||||
for universe in universes:
|
||||
if (
|
||||
item.get("instrumentType") == "EQUITY"
|
||||
item.get("instrumentType", instrument_type if detail_form else None) == "EQUITY"
|
||||
and type(item.get("delay")) is int
|
||||
and item["delay"] in (0, 1)
|
||||
and isinstance(item.get("region"), str)
|
||||
@@ -227,8 +235,10 @@ class ResearchMetadata:
|
||||
|
||||
async def refresh_availability(self, body):
|
||||
data = await upstream(self.client.field_availability(body.field_id, body.scope))
|
||||
if data.get("id") is not None and data["id"] != body.field_id:
|
||||
raise HTTPException(502, "平台返回字段与请求不一致,保留原可用性快照")
|
||||
content = {
|
||||
**normalize_availability(data),
|
||||
**normalize_availability(data, instrument_type=body.scope.instrument_type),
|
||||
"field_id": body.field_id,
|
||||
"scope": body.scope.model_dump(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user